Our goal was to design a simple button with a "smooth" look, without having much of a hassle to
set many properties like using the fill editor. You can easily create a Customized button using the TGDIPFill;
I have created a base for a Fill based button for you. The fill when the button is down, caption, click events, etc... must be added for completion. When installing it correctly you should be able to use the fill editor to create customized appearances for the button.
unit FillButton;
interface
uses
Classes, Controls, Messages, Graphics, GDIPFill, AdvGDIP;
type
TFillButton = class(TCustomControl)
private
Inside: Boolean;
FNormalFill: TGDIPFill;
FHoverFill: TGDIPFill;
procedure SetNormalFill(const Value: TGDIPFill);
procedure SetHoverFill(const Value: TGDIPFill);
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
protected
procedure FillChanged(Sender: TObject);
public
procedure Paint; override;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property NormalFill: TGDIPFill read FNormalFill write SetNormalFill;
property HoverFill: TGDIPFill read FHoverFill write SetHoverFill;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Fill Button', [TFillButton]);
end;
{ TFillButton }
procedure TFillButton.CMMouseEnter(var Msg: TMessage);
begin
inherited;
Inside := True;
invalidate;
end;
procedure TFillButton.CMMouseLeave(var Msg: TMessage);
begin
inherited;
Inside := False;
invalidate;
end;
constructor TFillButton.Create(AOwner: TComponent);
begin
inherited;
DoubleBuffered := True;
Inside := False;
FNormalFill := TGDIPFill.Create;
FNormalFill.OnChange := FillChanged;
FHoverFill := TGDIPFill.Create;
FHoverFill.OnChange := FillChanged;
FHoverFill.BeginUpdate;
FHoverFill.Color := clRed;
FHoverFill.EndUpdate;
end;
destructor TFillButton.Destroy;
begin
FNormalFill.Free;
FHoverFill.Free;
inherited;
end;
procedure TFillButton.FillChanged(Sender: TObject);
begin
invalidate;
end;
procedure TFillButton.Paint;
var
g: TGPGraphics;
r: TGPRectF;
begin
r := MakeRect(0, 0, Width - 1, Height - 1);
g := TGPGraphics.Create(Canvas.Handle);
if Inside then
HoverFill.Fill(g, r)
else
NormalFill.Fill(g, r);
g.Free;
end;
procedure TFillButton.SetHoverFill(const Value: TGDIPFill);
begin
FHoverFill.Assign(Value);
end;
procedure TFillButton.SetNormalFill(const Value: TGDIPFill);
begin
FNormalFill.Assign(Value);
end;
end.