Click here to Skip to main content
Click here to Skip to main content
Go to top

Appearance Customizable ComboBox

, 27 Mar 2007
Rate this:
Please Sign up or sign in to vote.
A class implementing .Net ComboBox Control that allows appearance customization.
Screenshot - demo.gif

Introduction

This class is derived from the .NET ComboBox class. It provides coloring and stylish customization to change the appearance of ComboBox's border and drop down button. An independent set of properties can be customized for both the GotFocus and LostFocus statuses. These properties are customizable from within the designer.

The original ComboBox control provided by .NET 2.0 Framework is very limited in the ability to customize the appearance. A lot of people have created their own custom made ComboBox instead of deriving from the ComboBox from .NET Framework. It might be due to the OnPaint function of the .NET ComboBox being inaccessible to the text box area of the ComboBox. You can allow overriding of the OnPaint function by using this statement in the constructor:

public CustomComboBox() : base()
{
    SetStyle(ControlStyles.UserPaint, true);
}

An alternative to re-drawing the ComboBox control is by overriding the WndProc function. However this approach can be significantly complicated to many beginners of C#, .NET or Win32 programming, especially when they want to continually select the suitable color and style to match the design of their application.

Background

This project is extended from the existing project, "Making Standard ComboBox appear flat" contributed by Fadrian Sudaman. I am impressed with what has been done by Fadrian Sudaman to draw on top of .NET ComboBox control by using WndProc.

Using the code

This class inherits from .NET ComboBox.

Instead of using:

ComboBox cboDemo = new ComboBox();

You can use:

ComboBox cboDemo = new CustomComboBox();
// or
CustomComboBox cboDemo = new CustomComboBox();

To use this class, reader needs to understand the standard functions, properties and events of .NET ComboBox, and a few new properties created in this inherited class.

Sample Image - maximum width is 600 pixels

Points of Interest

I have spent a lot of time to fix the flickering problem of this inherited control. I cut off a lot of unnecessary codes and simplified out the overridden WndProc function. I also changed the several "OnEvent" function and moved the Invalidate() to before base.OnEvent(e).

It still does flicker, especially if I set my video acceleration to None. However, I believe this should have minimized flickering into an acceptable level.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Eugenis

Singapore Singapore
Ng Pei Jiun, Eugenis, graduated from National University of Singapore. After worked for one year as VB .NET and C# .NET programmer, I had decided to do freelancing in order to experience more about SDLC and Project Management.
 
I am currently unemployed and having intermediate skill in C# .NET programming.

Comments and Discussions

 
QuestionChanging the Control Style to User Paint PinmemberiSwoop28-Sep-12 1:20 
Questionfixed PinmemberMember 41579894-May-12 11:53 
AnswerRe: fixed Pinmemberkomyoschong12-Aug-12 10:42 
GeneralRe: fixed Pinmemberomegarizla2-Nov-12 0:41 
QuestionError on Resize [modified] PinmemberMember 41579894-May-12 11:17 
QuestionHow to make combobox to drop up instead of drop down? PinmemberShrini4-Sep-07 23:08 
Questioncan you build this in in 2003? Pinmemberhonpher25-May-07 5:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 28 Mar 2007
Article Copyright 2007 by Eugenis
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid