怎样才能把tbutton的颜色修改成别的颜色?(100分)

C

chenlj

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样才能把tbutton的颜色修改成别的颜色?
不用第三方控件..
 
很简单的一个例子, 设置form1上的Button1的颜色为红色:
....
type
TForm1=class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
BtnBrush: TBrush;
OldBtnWndProc: TWndMethod;
procedure BtnWndProc(var Message: TMessage);
end;

....
procedure TForm1.FormCreate(Sender: TObject);
begin
BtnBrush := TBrush.Create;
BtnBrush.Style := bsSolid;
BtnBrush.Color := clRed;
OldBtnWndProc := Button1.WindowProc;
Button1.WindowProc := BtnWndProc;
end;

procedure TForm1.BtnWndProc(var Message: TMessage);
begin
case Message.Msg of
WM_CTLCOLORBTN:
Message.Result := BtnBrush.Handle;
else
OldBtnWndProc(Message);
end;
end;
 
顶部