HotKeyProperty (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

To use this example, create a form with a main menu component and a HotKey component. At design time, use the Menu designer to add menu items, including a "File" menu with subitems that include a "New" menu item. Add the following code to the OnCreate method of the form and the OnClick event of the File menu item.

Code

void __fastcall TForm1::File1Click(TObject *Sender)
{
  // Assign HotKey to the menu's File "New" item. 
  New1->ShortCut = HotKey1->HotKey;
}

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  // Default to "Ctrl + A".
  HotKey1->Modifiers.Clear();
  HotKey1->Modifiers << hkCtrl;
  // Don't allow shift or alt
  HotKey1->InvalidKeys.Clear();
  (HotKey1->InvalidKeys << hcShift) << hcAlt;
//  HotKey1->Visible = false;
}

Uses