我的未完成控件代码,但可以参考
//作用双态Image
unit ImageHot;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, Graphics;
type
TImageHot = class(TImage)
private
FGlyphOut: TPicture;
FGlyphIn: TPicture;
FIn: Boolean;
{ Private declarations }
procedure CMMouseEnter(var AMsg: TMessage);
message CM_MOUSEENTER;
procedure CMMouseLeave(var AMsg: TMessage);
message CM_MOUSELEAVE;
procedure SetGlyph(const Index: Integer; const Value: TPicture);
procedure DoPaint;
protected
{ Protected declarations }
procedure Loaded; override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property GlyphIn: TPicture index 1 read FGlyphIn write SetGlyph;
property GlyphOut: TPicture index 2 read FGlyphOut write SetGlyph;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Custom', [TImageHot]);
end;
{ TImageHot }
procedure TImageHot.CMMouseEnter(var AMsg: TMessage);
begin
FIn := true;
DoPaint;
end;
procedure TImageHot.CMMouseLeave(var AMsg: TMessage);
begin
Fin := False;
DoPaint;
end;
constructor TImageHot.Create(AOwner: TComponent);
begin
inherited Create(AOwner); ;
FGlyphOut := TPicture.Create;
FGlyphIn := TPicture.Create;
Self.Width := 75;
Self.Height := 25;
Self.Transparent := true;
Self.Center := true;
end;
destructor TImageHot.Destroy;
begin
FGlyphOut.Free;
FGlyphIn.Free;
inherited Destroy;
end;
procedure TImageHot.DoPaint;
var
x, y, i: integer;
begin
x := 0; y := 0;
canvas.pen.width := 1;
for i := 0 to 8 do
begin
canvas.pen.color := ClBlack;
canvas.moveto(left + Clientwidth + x,
top + y);
canvas.lineto(left + Clientwidth + x,
top + height + y);
canvas.pen.color := $00606060;
canvas.moveto(left + x,
top + Clientheight + y);
canvas.lineto(left + Clientwidth + x,
top + height + y);
x := x + 1;
y := y + 1;
end;
if FIn then
self.Picture := FGlyphIn
else
self.Picture := FGlyphOut;
end;
procedure TImageHot.Loaded;
begin
inherited;
Self.Picture.Assign(FGlyphOut);
Self.Canvas.Ellipse(0, 0, clientwidth, clientheight);
end;
procedure TImageHot.SetGlyph(const Index: Integer; const Value: TPicture);
begin
case Index of
1: FGlyphIn.Assign(Value);
2: FGlyphOut.Assign(Value);
end;
end;
end.