我正在使用启用了vcl样式的组合框,但是当我运行应用程序时,组合框使用的高亮颜色是窗口高亮颜色而不是vcl样式。
我如何解决这个问题,我的意思是在组合框中使用vcl风格的高亮颜色?
答案 0 :(得分:14)
据我所知,此问题的唯一解决方法是ownerdraw the combobox
尝试以下步骤
csOwnerDrawFixed
检查此示例代码
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 project的一部分),它为TListBox,TComboBox和TListView等组件提供了一组所有者绘制例程。
答案 1 :(得分:4)
这应该是RRUZ的一个。 :)
请参阅他的博文:http://theroadtodelphi.wordpress.com/2012/03/14/vcl-styles-and-owner-draw/
(保留代表他即将到来的答案,但你会得到一个开始^ _ ^)