type
TForm2 = class(TForm)
RectButton: TRectangle;
Label1: TLabel;
procedure RectButtonMouseEnter(Sender: TObject);
procedure RectButtonMouseLeave(Sender: TObject);
procedure RectButtonMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
procedure RectButtonClick(Sender: TObject);
procedure RectButtonMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
DefaultColor: TAlphaColor;
HiLightColor: TAlphaColor;
PressedColor: TAlphaColor;
procedure SetButtonColor(Sender: TObject; Color: TColor);
public
{ Public declarations }
end;
procedure TForm2.SetButtonColor(Sender: TObject; Color: TColor);
var
Button: TRectangle;
begin
if Sender is TRectangle then
begin
Button:= Sender as TRectangle;
Button.Fill.Color:= Color;
end;
end;
procedure TForm2.RectButtonClick(Sender: TObject);
begin
Label1.Text:= 'Button clicked';
end;
procedure TForm2.RectButtonMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
begin
SetButtonColor(Sender, PressedColor);
end;
procedure TForm2.RectButtonMouseEnter(Sender: TObject);
begin
SetButtonColor(Sender, HiLightColor);
end;
procedure TForm2.RectButtonMouseLeave(Sender: TObject);
begin
SetButtonColor(Sender, DefaultColor);
end;
procedure TForm2.RectButtonMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
begin
SetButtonColor(Sender, HiLightColor);
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
DefaultColor:= $FF0000D0;
HiLightColor:= $FF0000FF;
PressedColor:= $FF0000B0;
SetButtonColor(RectButton, DefaultColor);
end;
Head over and check out the full thread on the Embarcadero forum where the code snippet is posted.