Combobox does not use vcl highlight color.

I use combobox with vcl styles enabled, but when I run the application, the highlight color used in combobox is the color of the windows, not vcl styles.

How can I fix this, I mean using vcl style highlight color in combobox?

enter image description here

+8
delphi delphi-xe2 vcl-styles
source share
2 answers

As far as I know, the only workaround for this problem is ownerdraw combobox

Try the following steps.

  • Set the Style property for the csOwnerDrawFixed combo csOwnerDrawFixed
  • In the OnDrawItem event, use the vcl styes methods to draw combobox elements.

Check out this sample code.

 uses Vcl.Styles, Vcl.Themes, procedure TForm115.ComboBox1DrawItem(Control: TWinControl; Index: Integer; const ColorStates: array[Boolean] of TStyleColor = (scComboBoxDisabled, scComboBox); FontColorStates: array[Boolean] of TStyleFont = (sfComboBoxItemDisabled, sfComboBoxItemNormal); var LStyles : TCustomStyleServices; begin LStyles :=StyleServices; with Control as TComboBox do begin Canvas.Brush.Color := LStyles.GetStyleColor(ColorStates[Control.Enabled]); Canvas.Font.Color := LStyles.GetStyleFontColor(FontColorStates[Control.Enabled]); if odSelected in State then Canvas.Brush.Color := LStyles.GetSystemColor(clHighlight); Canvas.FillRect(Rect) ; Canvas.TextOut(Rect.Left+2, Rect.Top, Items[Index]); end; end; 

For more information, you can check out this article by Vcl Styles and Owner Draw . You can also use the Vcl.Styles.OwnerDrawFix block (part of the vcl-styles -utils project ), which includes a set of owners, draws procedures for components such as TListBox, TComboBox and TListView.

+14
source share

This should be one for RRUZ. :)
See His blog post: http://theroadtodelphi.wordpress.com/2012/03/14/vcl-styles-and-owner-draw/

(save your reputation for your early reply, but you will start ^ _ ^)

+4
source share

All Articles