Mega Code Archive

 
Categories / Delphi / VCL
 

Making a label into a hot link

Title: Making a label into a hot-link Question: How do I get a URL effect on my label? Answer: In my aboutbox, I like to have a clickable link for the URL, here's the easy way of doing it: declarations procedure Label4Click(Sender: TObject); protected procedure WndProc(var Message : TMessage); override; definitions: procedure TAboutBox.WndProc(var Message : TMessage); begin if Message.LParam = Longint(Label4) then begin if (Message.Msg = CM_MOUSELEAVE) then begin Label4.Font.Color := clWindowText; Label4.Font.Style := Label4.Font.Style - [fsUnderline]; end; if (Message.Msg = CM_MOUSEENTER) then begin Label4.Font.Color := clBlue; Label4.Font.Style := Label4.Font.Style + [fsUnderline]; end; end; inherited WndProc(Message); end; procedure TAboutBox.Label4Click(Sender: TObject); begin ShellExecute(MainFrm.Handle, 'open', PChar('http://www.url.com/'), nil, PChar(ExtractFilePath('http://www.url.com/')), SW_SHOWNORMAL) end; Obviously change all the Label4s to the name of your label. works fine in delphi 5 and win2k/95/98 and NT4. Should also work great with all versions of delphi.