我正在使用啓用了vcl樣式的組合框,但是當我運行應用程序時,組合框使用的高亮顏色是窗口高亮顏色,而不是vcl樣式。組合框不使用vcl樣式高亮顏色。
我該如何解決這個問題,我的意思是在組合框中使用vcl樣式高亮顏色?
我正在使用啓用了vcl樣式的組合框,但是當我運行應用程序時,組合框使用的高亮顏色是窗口高亮顏色,而不是vcl樣式。組合框不使用vcl樣式高亮顏色。
我該如何解決這個問題,我的意思是在組合框中使用vcl樣式高亮顏色?
據我所知,唯一的解決方法對於這個問題,是的OwnerDraw組合框
請嘗試以下步驟
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等組件繪製例程。
這應該是一個RRUZ。 :)
見他的博客:http://theroadtodelphi.wordpress.com/2012/03/14/vcl-styles-and-owner-draw/
(保持代表爲他即將到來的答案,但你會得到一個開始^ _ ^)
+1,RRUZ規則。 – 2012-03-16 18:17:07
是啊,我在等待第一個問題,詢問如何用WMI查詢VCL樣式..... – 2012-03-16 18:39:34
@David,LOL ... – 2012-03-16 18:52:58