8
votes

I'm using a combobox with the vcl styles enabled, but when i run the application the highlight color used by the combobox is the windows highlight color and not of the vcl styles.

How i can fix this, i mean use the vcl style highlight color in the combobox?

enter image description here

2

2 Answers

14
votes

As far i know, the only workaround for this issue, is ownerdraw the combobox

Try these steps

  1. Set the Style property of the combobox to csOwnerDrawFixed
  2. In the OnDrawItem event use the vcl styes methods to draw the combobox items.

Check 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 info you can check this article Vcl Styles and Owner Draw. Also you can use the Vcl.Styles.OwnerDrawFix unit (part of the vcl-styles-utils project) which incudes a set of owner draws routines for components like TListBox, TComboBox and TListView.

4
votes

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

(keep the rep for his soon-to-come answer, but you'll get a start ^_^)