Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

combobox doesn't use vcl style highlight color.

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

like image 916
Salvador Avatar asked Mar 16 '12 17:03

Salvador


1 Answers

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.

like image 178
RRUZ Avatar answered Nov 04 '22 22:11

RRUZ