D
duanbukui
Unregistered / Unconfirmed
GUEST, unregistred user!
整个单元是这样的:
unit ImgBtn;
interface
uses
SysUtils, Classes, Controls, ExtCtrls, Messages, StdCtrls, Windows, Graphics,
Forms ;
type
TImgBtn = class(TImage)
private
CLabel : TLabel;
FGetCaption: TCaption;
procedure MouseIn(var MSG : TMessage); message CM_MOUSEENTER;
procedure MouseOut(var MSG : TMessage); message CM_MOUSELEAVE;
procedure SetCaption(const Value: TCaption);
protected
{ Protected declarations }
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
published
property Caption : TCaption read FGetCaption write SetCaption;
property OnClick ; //继承点击事件
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Dpider', [TImgBtn]);
end;
{ TChangeImage }
constructor TImgBtn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
//组件部分=======================
Caption := '';
Width := 32 ;
Height := 32 ;
ShowHint := True ;
Stretch := True ;
Transparent := True ;
//标签部分=======================
if CLabel = nil then
CLabel := TLabel.Create(nil);
CLabel.Parent := TWinControl(self) ;
CLabel.Left := Left - ((CLabel.Width-Width) div 2) ;
CLabel.Top := Top +Height+5 ;
CLabel.Visible := True ;
CLabel.Transparent := True ;
CLabel.ShowHint := True ;
CLabel.Hint := Hint ;
CLabel.Font.Size := 9;
CLabel.Font.Color := clBlack;
CLabel.Font.Name := '宋体';
CLabel.Font.Charset := GB2312_CHARSET;
CLabel.AutoSize := True;
CLabel.Caption := FGetCaption;
end;
destructor TImgBtn.Destroy;
begin
inherited Destroy;
if CLabel<>nil then CLabel.Hide ;
end;
procedure TImgBtn.MouseIn(var MSG: TMessage);
begin
if CLabel<>nil then
begin
CLabel.Font.Color := clBlue;
CLabel.Font.Style := CLabel.Font.Style+[fsUnderline] ;
Screen.Cursor := crHandPoint ;
end ;
end;
procedure TImgBtn.MouseOut(var MSG: TMessage);
begin
if CLabel <> nil then
begin
CLabel.Font.Color := clBlack;
CLabel.Font.Style := CLabel.Font.Style-[fsUnderline] ;
Screen.Cursor := crDefault ;
end ;
end;
procedure TImgBtn.SetCaption(const Value: TCaption);
begin
FGetCaption := Value;
if CLabel <> nil then
CLabel.Caption := FGetCaption;
end;
end.
unit ImgBtn;
interface
uses
SysUtils, Classes, Controls, ExtCtrls, Messages, StdCtrls, Windows, Graphics,
Forms ;
type
TImgBtn = class(TImage)
private
CLabel : TLabel;
FGetCaption: TCaption;
procedure MouseIn(var MSG : TMessage); message CM_MOUSEENTER;
procedure MouseOut(var MSG : TMessage); message CM_MOUSELEAVE;
procedure SetCaption(const Value: TCaption);
protected
{ Protected declarations }
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
published
property Caption : TCaption read FGetCaption write SetCaption;
property OnClick ; //继承点击事件
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Dpider', [TImgBtn]);
end;
{ TChangeImage }
constructor TImgBtn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
//组件部分=======================
Caption := '';
Width := 32 ;
Height := 32 ;
ShowHint := True ;
Stretch := True ;
Transparent := True ;
//标签部分=======================
if CLabel = nil then
CLabel := TLabel.Create(nil);
CLabel.Parent := TWinControl(self) ;
CLabel.Left := Left - ((CLabel.Width-Width) div 2) ;
CLabel.Top := Top +Height+5 ;
CLabel.Visible := True ;
CLabel.Transparent := True ;
CLabel.ShowHint := True ;
CLabel.Hint := Hint ;
CLabel.Font.Size := 9;
CLabel.Font.Color := clBlack;
CLabel.Font.Name := '宋体';
CLabel.Font.Charset := GB2312_CHARSET;
CLabel.AutoSize := True;
CLabel.Caption := FGetCaption;
end;
destructor TImgBtn.Destroy;
begin
inherited Destroy;
if CLabel<>nil then CLabel.Hide ;
end;
procedure TImgBtn.MouseIn(var MSG: TMessage);
begin
if CLabel<>nil then
begin
CLabel.Font.Color := clBlue;
CLabel.Font.Style := CLabel.Font.Style+[fsUnderline] ;
Screen.Cursor := crHandPoint ;
end ;
end;
procedure TImgBtn.MouseOut(var MSG: TMessage);
begin
if CLabel <> nil then
begin
CLabel.Font.Color := clBlack;
CLabel.Font.Style := CLabel.Font.Style-[fsUnderline] ;
Screen.Cursor := crDefault ;
end ;
end;
procedure TImgBtn.SetCaption(const Value: TCaption);
begin
FGetCaption := Value;
if CLabel <> nil then
CLabel.Caption := FGetCaption;
end;
end.