|
Turning a Memo into a "hyperlink"
The main difference between turning a Label and a Memo into a hyperlink is a Memo can
recieve focus.
To turn a Memo into a hyperlink:
- Change the BorderStyle to bsNone
- Change the Color to clBtnFace
- Change the label's font property to make it blue and under lined
or whatever you think a hyperlink should look like
- Change Cursor to crHandPoint
- Change ReadOnly to true
- Design a PopUp menu for it without useless Menus (since ReadOnly is true) like Undo,
Delete, Cut, and Paste (and
possibly Select All depending on excactly how you implement you hyperlink)
- Add the code, which is given below, for various events (assuming the Memo is named
EMailMemo)
//The "real" power of the hyperlink is in clicking it
procedure TForm.EMailMemoClick(Sender: TObject);
begin
{possibly Close the form here}
ShellExe ('mailto:' + EMailMemo.Text + '?subject=Code%20Edit');
end;
procedure TForm.EMailMemoEnter(Sender: TObject);
begin
EMailMemo.SelectAll;//so the user can see it's focused
end;
procedure TForm.EMailMemoKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_INSERT) and (ssCtrl in Shift) then exit;//allow Memo to copy
if Key = VK_ESCAPE then Close;//optional like before
Key := 0;//don't allow other Key processing
end;
{pressing enter should do the same things a clicking the hyperlink}
procedure TForm.EMailMemoKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then EMailMemo.OnClick (Sender);
end;
|