forked from JBontes/Life32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyLinkLabel.pas
126 lines (103 loc) · 2.85 KB
/
MyLinkLabel.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
unit MyLinkLabel;
interface
uses
Windows,
Messages,
SysUtils,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
StdCtrls,
Shellapi;
Type
TMyLinkLabel = class(TStaticText)
private
FLinkDestination: string;
FLinkColor: TColor;
FLinkColorMouseMove: TColor;
protected
procedure SetLinkDestination(const Value: string);
procedure Click; override;
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
procedure CMFontChanged(var Msg: TMessage); message CM_FONTCHANGED;
procedure SetLinkColor(Value: TColor);
public
constructor Create(AOwner: TComponent); override;
published
property LinkDestination: string read FLinkDestination write SetLinkDestination;
property LinkColor: TColor read FLinkColor write SetLinkColor;
property LinkColorMouseMove: TColor read FLinkColorMouseMove write FLinkColorMouseMove;
end;
{.$IF declared(TLinkLabel)}
{.$ELSE}
procedure Register;
{.$ENDIF}
implementation
uses
System.UITypes;
//******************* TLinkLabel.Create *************************
constructor TMyLinkLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
LinkDestination:= 'http://';
Cursor:= crHandPoint;
Font.Color:= clBlue;
Font.Style:= Font.Style + [fsUnderline];
FLinkColor:= clBlue;
FLinkColorMouseMove:= clRed;
end;
//******************* TLinkLabel.SetLinkDestination *************************
procedure TMyLinkLabel.SetLinkDestination(const Value: string);
begin
if Value <> FLinkDestination then begin
FLinkDestination:= AnsiLowerCase(Value);
end;
end;
//******************* TLinkLabel.Click *************************
procedure TMyLinkLabel.Click;
begin
if FLinkDestination <> '' then begin
ShellExecute(TWinControl(Owner).Handle, 'open', PChar(LinkDestination), nil, nil, SW_SHOW);
end;
inherited Click;
end;
//******************* TLinkLabel.CMMouseEnter *************************
procedure TMyLinkLabel.CMMouseEnter(var Msg: TMessage);
begin
Font.Color:= FLinkColorMouseMove;
Refresh;
end;
//******************* TLinkLabel.CMMouseLeave *************************
procedure TMyLinkLabel.CMMouseLeave(var Msg: TMessage);
begin
Font.Color:= FLinkColor;
Refresh;
end;
//******************* TLinkLabel.SetLinkColor *************************
procedure TMyLinkLabel.SetLinkColor(Value: TColor);
begin
if Value <> FLinkColor then begin
FLinkColor:= Value;
Font.Color:= FLinkColor;
Refresh;
end;
end;
//******************* TLinkLabel.CMFontChanged *************************
procedure TMyLinkLabel.CMFontChanged(var Msg: TMessage);
begin
if csDesigning In ComponentState then begin
FLinkColor:= Font.Color;
Refresh;
end;
end;
{.$IF declared(TLinkLabel)}
{.$ELSE}
procedure Register;
begin
RegisterComponents('Additional', [TMyLinkLabel]);
end;
{.$ENDIF}
end.