【发布时间】:2015-09-01 11:12:44
【问题描述】:
我有一个TComboBox 和Style:= csOwnerDrawVariable;,我想用黑色而不是“灰色”显示禁用的Font。
这是我从这个来源得到的:
procedure TCustomComboBox.WndProc(var Message: TMessage);
begin
case Message.Msg of
CN_CTLCOLORMSGBOX .. CN_CTLCOLORSTATIC, //48434..48440
WM_CTLCOLORMSGBOX .. WM_CTLCOLORSTATIC:
begin
Color:= GetBackgroundColor; // get's the current background state
Brush.Color:= Color;
end;
end;
inherited;
end;
但我希望内部Edit 控件的字体颜色为黑色。
如果我在WndProc 更改Font.Color:= clBlack 或其他任何事情都不会发生。
Google 搜索给了我一些关于将 TEdit 更改为只读的提示,但这对我没有帮助。
更新
这是我从@Abelisto 获得提示后的简短解决方案。
TCustomComboBox = class (TComboBox)
protected
procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
end;
procedure TCustomComboBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
if odComboBoxEdit in State then begin // If we are drawing item in the edit part of the Combo
if not Enabled then
Canvas.Font.Color:= clBlack; // Disabled font colors
Canvas.Brush.Color:= GetBackgroundColor; // Get the right background color: normal, mandatory or disabled
end;
inherited DrawItem(Index, Rect, State);
end;
【问题讨论】:
-
你在哪里更改 Font.Color ?在 WndProc 或其他地方?
-
@GuidoG 是的,也尝试过 WndProc,但无法更改编辑控件的字体。
-
不确定它是否有效,但在 wndprod 中,画笔用于背景,而 Pen 用于前景。尝试更改 pen.color
-
然后是
SetTextColor,但请注意inherited调用会将其返回。 -
@GuidoG thx for the tipp,但它不起作用
标签: delphi fonts combobox controls delphi-xe2