Search code examples
custom-controlsc++builderbuildervcl

Custom draw ComboBox to reduce size of arrow [C++ Builder XE/2]


I've got a string (horizontal) of drop down ComboBoxes. Considering the data in them is so small, the drop down arrow takes up a lot of space and makes the entire thing look ugly.

So I'm wondering about making the 'arrow' only turn on during mouse hover, or something similar. But I don't want other people to look at it and have their eyes bleed. I know, I know, there are reasons for UI standards, but this seems like an exception to me. I'm assuming that if someone wants to change the data, they'll at least hover the mouse over it, if not click it.

Target is C++ Builder XE2, but Visual C++ targeted examples are fine too. I don't expect a full working example, just a push in the right direction (unless of course there is a fully working component out there already waiting for drag and drop, no point reinventing in that case)


Solution

  • You don't have any control over the drop-down arrow. It is part of the underlying ComboBox window that is managed by the OS, not the VCL.

    What I would suggest you do is use TEdit instead of TComboBox, and then create a separate TForm that has a TListBox on it. When the user hovers over a TEdit or clicks on it, you can display the TForm and update its TListBox to contain the relavant items. If the user clicks on an item in the TListBox, you can assign that string value to the current TEdit. This gives you more control over the look-and-feel of the TListBox display, give you more controls over its on-screen positioning, maybe even add some special effects like fade-in/out via the TForm.AlphaBlend property, etc.