unit NetLabel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,ShellAPI;
type
THyperLink = (hlHTTP,hlMail,hlTelnet,hlGopher,hlNews,hlFTP);
type
TNetLabel = class(TLabel)
private
FHyperLinkKind : THyperLink; //指定超链接的类型
FHyperLink : String;//超链接的目标地址
FHLinkColor : TColor;//鼠标移动到超链接时的颜色
FVLinkColor : TColor; //目标被访问后的颜色
FColor : TColor;//存放颜色值的临时变量
procedure CMMouseEnter(var AMsg : TMessage);message CM_MOUSEENTER;
procedure CMMouseLeave(var AMsg : TMessage);message CM_MOUSELEAVE;
//分别处理鼠标移进、移出的消息
{ Private declarations }
protected
{ Protected declarations }
public
constructor Create(AOwner : TComponent);Override;
procedure Click;Override;
{ Public declarations }
published
property HyperLinkKind : THyperLink read FHyperLinkKind
Write FHyperLinkKind
default hlMail;
property HyperLink : string read FHyperLink
Write FHyperLink;
property HLinkColor : TColor read FHLinkColor
Write FHLinkColor
default clBlue;
property VLinkColor : TColor read FVLinkColor
Write FVLinkColor
default clNavy;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Tsinghua', [TNetLabel]);
end;
procedure TNetLabel.CMMouseEnter(Var AMsg : TMessage);
begin
FColor := Font.Color;
Font.Color := FHLinkColor;
Font.Style := Font.Style + [fsUnderLine];
end;
procedure TNetLabel.CMMouseLeave(Var AMsg : TMessage);
begin
Font.Color := FColor;
Font.Style := Font.Style - [fsUnderLine];
end;
constructor TNetLabel.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FHyperLinkKind := hlHTTP;
FHyperLink := 'www.thtf.com.cn';
FHLinkColor := clBlue;
FVLinkColor := clNavy;
with Self do
begin
Cursor := crHandPoint;
Caption := '清华同方股份有限公司22';
Font.Color := clMaroon;
Font.Name := '宋体';
Font.Size := 9;
FColor := Font.Color;
end;
end;
procedure TNetLabel.Click;
begin
Inherited Click;
if FHyperLink <> '' then
begin
case FHyperLinkKind of
hlHTTP : ShellExecute(Parent.Handle,nil,
PChar('HTTP://'+FHyperLink),
nil,nil,sw_ShowNormal);
hlMail : ShellExecute(Parent.Handle,nil,
PChar('MailTo:'+FHyperLink),
nil,nil,sw_ShowNormal);
hlFTP : ShellExecute(Parent.Handle,nil,
PChar('FTP://'+FHyperLink),
nil,nil,sw_ShowNormal);
hlNews : ShellExecute(Parent.Handle,nil,
PChar('News:'+FHyperLink),
nil,nil,sw_ShowNormal);
hlGopher : ShellExecute(Parent.Handle,nil,
PChar('Gopher://'+FHyperLink),
nil,nil,sw_ShowNormal);
hlTelnet : ShellExecute(Parent.Handle,nil,
PChar('Telnet:'+FHyperLink),
nil,nil,sw_ShowNormal);
end;
end;
FColor := FVLinkColor;
end;
end.