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?
As far i know, the only workaround for this issue, is ownerdraw the combobox
Try these steps
csOwnerDrawFixed
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With