个你写一各吧,其他功能自己去加
unit XPButton;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TXPButton = class(TCustomControl)
private
FCaption: string;
FMouseIn: Boolean;
FICON: TICON;
procedure SetMouseIn(const Value: Boolean);
procedure SetICON(const Value: TICON);
protected
procedure Paint; override;
property MouseIn: Boolean read FMouseIn write SetMouseIn;
procedure CMMouseenter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseleave(var Message: TMessage); message CM_MOUSELEAVE;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Caption: string read FCaption write FCaption;
property ICON: TICON read FICON write SetICON;
property OnClick;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('WRCtrl', [TXPButton]);
end;
procedure TXPButton.CMMouseenter(var Message: TMessage);
begin
inherited;
MouseIn := True;
end;
procedure TXPButton.CMMouseleave(var Message: TMessage);
begin
inherited;
MouseIn := False;
end;
constructor TXPButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FICON := TICON.Create;
end;
destructor TXPButton.Destroy;
begin
FICON.Free;
inherited Destroy;
end;
procedure TXPButton.Paint;
var
ARect : TRect;
ICONPos : Integer;
begin
inherited Paint;
ARect := ClientRect;
with Canvas, ARect do
begin
Brush.Color := RGB(255, 251, 247);
FillRect(Arect);
if (FMouseIn) and (not (csDesigning in ComponentState)) then
begin
Inc(Left, 2);
Inc(Top, 2);
Brush.Style := bsSolid;
brush.Color := clGray;
Pen.Color := clMenu;
RoundRect(Left, Top, Right, Bottom, 5, 5);
brush.Color := RGB(175, 183, 207);
Dec(Left, 2);
Dec(Top, 2);
Dec(Right, 2);
Dec(Bottom, 2);
Pen.Color := clBlack;
RoundRect(Left, Top, Right, Bottom, 5, 5);
end;
if FICON <> nil then
begin
ICONPos := (Height - FICON.Height) div 2;
Draw(ICONPos, ICONPos, FICON);
end;
Brush.Style := bsClear;
Inc(ARect.Left, ICONPos + FICON.Width);
DrawText(Handle, PChar(FCaption), -1, ARect, DT_CENTER or DT_SINGLELINE or
DT_VCENTER);
end;
end;
procedure TXPButton.SetICON(const Value: TICON);
begin
if Assigned(Value) then
FICON.Assign(Value);
end;
procedure TXPButton.SetMouseIn(const Value: Boolean);
begin
FMouseIn := Value;
Repaint;
end;
end.