Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a TLabel behave like a hyperlink in Delphi?

How do I make a TLabel behave like a hyperlink in Delphi?

Note: I'm not interested in using TLinkLabel because of backwards compatibility issues.

like image 472
Rowan Avatar asked Aug 25 '09 06:08

Rowan


2 Answers

Colour it blue, set style to underline and add an OnClick event!

procedure TForm1.Label1Click(Sender: TObject);
var
  MyLink: string;
begin
  MyLink := 'http://www.mysite.com/';
  ShellExecute(Application.Handle, PChar('open'), PChar(MyLink),    
   nil, nil, SW_SHOW);
end;
like image 108
DmitryK Avatar answered Nov 08 '22 09:11

DmitryK


It depends on what you require of your hyperlinks. I'd just...

  • set the font color to blue
  • use the OnMouse[Enter|Leave|Move] events to appropriately apply the underline style to the font
  • use the OnClick event to spawn a browser & change the font color, as desired.
like image 45
moobaa Avatar answered Nov 08 '22 08:11

moobaa