我有一個TComboBox
與Style:= csOwnerDrawVariable;
,我想顯示禁用的Font
顏色爲黑色,而不是「灰色」。如何更改禁用TComboBox(Delphi)的字體顏色?
這就是我得到這個來源:
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
控制的字體顏色。
如果我更改Font.Color:= clBlack
在WndProc
或別的什麼都沒有發生。
谷歌搜索給了我一些關於將TEdit
更改爲只讀的tipps,但這對我還沒有幫助。
更新
這裏現在是@Abelisto得到TIPP後,我的短期解決方案。
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
@GuidoG耶也嘗試過WndProc,但不能改變編輯控件的字體。 – punker76
不知道它是否有效,但在wndprod中,畫筆用於背景,筆用於前景。嘗試改變筆。顏色 – GuidoG