combobox不使用vcl风格的高亮颜色.

Sal*_*dor 8 delphi delphi-xe2 vcl-styles

我正在使用启用了vcl样式的组合框,但是当我运行应用程序时,组合框使用的高亮颜色是窗口高亮颜色而不是vcl样式.

我怎么能解决这个问题,我的意思是在组合框中使用vcl风格的高亮颜色?

在此输入图像描述

RRU*_*RUZ 14

据我所知,这个问题的唯一解决方法是拥有组合框

尝试这些步骤

  1. 将组合框的Style属性设置为 csOwnerDrawFixed
  2. 在OnDrawItem事件中,使用vcl styes方法绘制组合框项.

检查此示例代码

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;
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请查看此文章Vcl Styles and Owner Draw.您还可以使用Vcl.Styles.OwnerDrawFix单元( vcl-styles-utils项目的一部分),它包含一组所有者为TListBox,TComboBox和TListView等组件绘制例程.