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

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds