Mega Code Archive

 
Categories / Delphi / VCL
 

Keyboard shortcut to a component that has no caption

Question: How can I create a keyboard shortcut to a component that has no caption? Answer: One work around is to leverage the FocusControl property of TLabel. The following example demonstrates using an invisible label control to create a keyboard shortcut to a memo control. The shortcut will respond to the Alt+M key combination. To use this example, place a label, a memo, and several other controls that receive focus. Run the application, move focus to a control other than "Memo1", and key in -M. You should see focus move to Memo1. Example: procedure TForm1.FormCreate(Sender: TObject); begin Label1.Visible := false; Label1.Caption := '&M'; Label1.FocusControl := Memo1; end;