delphikeyboard-shortcutsdelphi-2007acceleratorkey

How to remove the accelerator hot key '&' character?


I'm using the '&' character for using accelerator keys with my TLabel controls. In this way, the user can press Alt+Character after the & in order to focus controls on the form.

Example:

var
  MyLabel : TLabel;
  MyEdit : TEdit;
begin
  MyEdit := TEdit.Create(Self);
  MyEdit.Left := 20;
  MyEdit.Top := 40;
  MyEdit.Parent := Self;

  MyLabel := TLabel.Create(Self);
  MyLabel.FocusControl := MyEdit;
  MyLabel.Caption := '&Test';
  MyLabel.Left := 20;
  MyLabel.Top := 20;
  MyLabel.Parent := Self;
end;

In this case, MyLabel appears with the 'T' character underlined and pressing Alt+T causes MyEdit to be focused.

enter image description here

How can I get MyLabel.Caption without the '&' character? Is there any built in function for doing this?

I'm expecting to get 'Test' string instead of '&Test'


Solution

  • You are looking for the StripHotkey function.