Colored ComboBox

If you have ever tried, you must have noticed that coloring a ComboBox is not that trivial at all. If you want to color only the edit and/or the list box, it is very simple, and I am sure you know how to do that. But, if you want ALL the combo to look different, including the Windows' Gray button (near the edit box), it is not that simple; you have to draw it yourself. I will show how to do it easily and effectively. An example for my colored combo-box can be viewed in the following picture:

In short, the main "technique" here is holding a CBrush (of course) as a member, and the COLORREF I want to use. In the CtlColor method, I change the colors, but the main work is done in the OnPaint() method. There, I actually paint the control by myself—and yes, including the irritating gray button; we all want to change its color! (It is not that simple because we have to know where this button is located—on the left side or on the right, and more...)

Another major problem is in case of the drop-down LIST. In this case, there is no "CEdit" inside the combo-box, so even if we paint it colorfully, the framework paints it back to the Windows' default. Because of this, I am forbidden to use this style, but manage it differently my way: I had to keep CColoredEdit in any case, and another flag that lets me know what style the user wants to use. CColoredEdit enables me to rule the edit part of the combo, even with a drop list. In this case, I do not use CStatic, but I give a ReadOnly style to this CEDit. There are other problems in the drop-LIST mode: Because there is no CEdit, Windows allows you to open the list-box by clicking the mouse over the static area. In addition, when the list is dropped down, pressing the Enter key selects the item and closes the list. For this purpose, I inherited the CColoredEdit, and created the CColoredEditInCombo class, which is dedicated to work with my comboBox. It handles the mouse and keyboard events, and does the work like Windows.

The biggest problem that I have not solved yet—but I will!!—is the issue of ScrollBars inside the dropped-down list. I have to change their colors too, but as I started working on it, I saw it needs a lot of work. So, in the meantime, you can use this Combo, and if you find a good way to color the ScrollBars, let me know! If I find a way sooner, I will let you know.

To summarize, this Combo works (for now) ONLY in drop-down mode. (Who works with simple mode anyway???) If you want to work with the drop LIST, use my interface easily.

Enjoy.



About the Author

Ohad Redlich

programmer, B.Sc Computer Science M.B.A Management and Business Administration

Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Due to internal controls and regulations, the amount of long term archival data is increasing every year. Since magnetic tape does not need to be periodically operated or connected to a power source, there will be no data loss because of performance degradation due to the drive actuator. Read this white paper to learn about a series of tests that determined magnetic tape is a reliable long-term storage solution for up to 30 years.

Most Popular Programming Stories

More for Developers

RSS Feeds