例子来了:
unit UltraLabel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TUltraLabel = class(TLabel)
private
FTrack:boolean;
FTrackColor:Tcolor;
FstateColor:Tcolor;
Ftrackline:boolean;
Fonmouseenter:Tnotifyevent;
Fonmouseleave:Tnotifyevent;
procedure settrackcolor(value:Tcolor);
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
protected
public
constructor Create(AOwner: TComponent); override;
published
property Track:boolean read Ftrack write Ftrack;
property Trackline:boolean read Ftrackline write Ftrackline;
property Trackcolor:Tcolor read Ftrackcolor write settrackcolor;
property OnMouseEnter:Tnotifyevent read Fonmouseenter write Fonmouseenter;
property OnMouseLeave:Tnotifyevent read Fonmouseleave write Fonmouseleave;
end;
procedure Register;
implementation
constructor TUltraLabel.Create(AOwner: TComponent);
begin
inherited create(Aowner);
Fstatecolor:=font.Color;
Ftrack:=true;
Ftrackcolor:=clred;
FtrackLine:=true;
// cursor:=CrHandPoint;
end;
procedure TUltraLabel.CMMouseEnter(var Message: TMessage);
begin
if track then
begin
font.color:=Ftrackcolor;
if Ftrackline then font.Style:=[fsunderline];
end;
if assigned(Fonmouseenter)then Fonmouseenter(self);
end;
procedure TUltraLabel.CMMouseLeave(var Message: TMessage);
begin
if track then
begin
font.color:=FStatecolor;
if Ftrackline then font.Style:=[];
end;
if assigned(Fonmouseleave)then Fonmouseleave(self);
end;
procedure TultraLabel.settrackcolor(value:Tcolor);
begin
fTrackcolor:=value;
Fstatecolor:=font.Color;
Invalidate;
end;
procedure Register;
begin
RegisterComponents('Ydejun', [TUltraLabel]);
end;
end.