找到一个 WM_CTLCOLOREDIT 消息的例子,应该可以实现一部分要求的,关键在于 WM_CTLCOLOREDIT 消息的处理:
虽然还是不能处理 Enabled = False 的情况,但是我只能做到这一步了,自己再想想办法吧。
TEdit 和 TDBEdit 应该是一样的。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
ListBox1: TListBox;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FBrush: HBRUSH;
procedure WMCTLCOLOREDIT(var Msg: TMessage); message WM_CTLCOLOREDIT;
procedure WMCTLCOLORBTN(var Msg: TMessage); message WM_CTLCOLORBTN;
procedure WMCTLCOLORLISTBOX(var Msg: TMessage); message WM_CTLCOLORLISTBOX;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TForm1 }
procedure TForm1.WMCTLCOLOREDIT(var Msg: TMessage);
begin
SetTextColor(Msg.wParam, clWhite);
SetBkColor(Msg.wParam, clGreen);
SetBkMode(Msg.wParam, OPAQUE);
Msg.Result := FBrush;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FBrush := CreateSolidBrush(clRed);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DeleteObject(FBrush);
end;
procedure TForm1.WMCTLCOLORBTN(var Msg: TMessage);
begin
SetTextColor(Msg.wParam, clRed);
SetBkColor(Msg.wParam, clRed);
Msg.Result := FBrush;
end;
procedure TForm1.WMCTLCOLORLISTBOX(var Msg: TMessage);
begin
SetTextColor(Msg.wParam, clWhite);
SetBkColor(Msg.wParam, clGreen);
SetBkMode(Msg.wParam, OPAQUE);
Msg.Result := FBrush;
end;
end.