Type | Description | |||
ID as Long | A long expression that specifies the identifier of the item being activated when accelerator key is pressed. | |||
KeyCode as Integer | A long expression that defines the code of the key being the item's accelerator | |||
CtrlKey as Variant | A boolean expression that indicates whether the KeyCode key and CTRL key defines the accelerator | |||
ShiftKey as Variant | A boolean expression that indicates whether the KeyCode key and SHIFT key defines the accelerator | |||
AltKey as Variant | A boolean expression that indicates whether the KeyCode key and ALT key defines the accelerator |
Use the AddAcelerator method to add accelerators to the menu. The AddAccelerator associates a key to an item. If the user presses one of the control's accelerator keys it fires the Select event. The Select event is not fired if the user presses an accelerator key that's associated to a disabled or a hidden item. Use the Visible property to hide an item. Use the Enabled property to disable an item. Use the form's KeyDown event to get the code of the key you press. Use the Add method to add new items.
The following VB sample assigns the CTRL+F accelerator to an item:
With ExMenu1 With .Items With .Add("Popup", EXMENULibCtl.SubMenu, 1221).SubMenu .Add "File CTRL+F", EXMENULibCtl.Default, 1222 End With End With .AddAcelerator 1222, KeyCodeConstants.vbKeyF, True, False, False .Refresh End With
If you run the sample, and press CTRL+F combination, the Select event is fired.
The following C++ sample assigns the CTRL+F accelerator to an item:
COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR; CItem item = m_menu.GetItems().Add( "Popup", COleVariant( long(2) /*SubMenu*/), COleVariant(long(1221))); CItem subItem = item.GetSubMenu().Add( "File CTRL+F", COleVariant( long(0) /*Default*/), COleVariant(long(1222)) ); m_menu.AddAcelerator( 1222, 70, COleVariant( VARIANT_TRUE ), COleVariant( VARIANT_FALSE ), COleVariant( VARIANT_FALSE ) ); m_menu.Refresh();
The following VB.NET sample assigns the CTRL+F accelerator to an item:
With AxExMenu1 With .Items With .Add("Popup", EXMENULib.ItemTypeEnum.SubMenu, 1221).SubMenu .Add("File CTRL+F", EXMENULib.ItemTypeEnum.Default, 1222) End With End With .AddAcelerator(1222, Convert.ToInt32(Keys.F), True, False, False) .CtlRefresh() End With
The following C# sample assigns the CTRL+F accelerator to an item:
EXMENULib.Menu menu = axExMenu1.Items.Add("Popup", EXMENULib.ItemTypeEnum.SubMenu, 1221).SubMenu; menu.Add("File CTRL+F", EXMENULib.ItemTypeEnum.Default, 1222); axExMenu1.AddAcelerator(1222, Convert.ToInt16(Keys.F), true, false, false); axExMenu1.CtlRefresh();
The following VFP sample assigns the CTRL+F accelerator to an item:
With thisform.ExMenu1 With .Items With .Add("Popup", 2, 1221).SubMenu .Add("File CTRL+F", 0, 1222) EndWith EndWith .AddAcelerator(1222, 70, .t., .f., .f.) .Object.Refresh EndWith