8

我正在使用启用了 vcl 样式的组合框,但是当我运行应用程序时,组合框使用的突出显示颜色是窗口突出显示颜色,而不是 vcl 样式。

我该如何解决这个问题,我的意思是在组合框中使用 vcl 样式突出显示颜色?

在此处输入图像描述

4

2 回答 2

14

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

试试这些步骤

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

检查此示例代码

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;

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

于 2012-03-16T19:44:59.900 回答
4

这应该是RRUZ的一个。:)
见他的博文:http: //theroadtodelphi.wordpress.com/2012/03/14/vcl-styles-and-owner-draw/

(保持代表他即将到来的答案,但你会得到一个开始^_^)

于 2012-03-16T17:39:05.210 回答