Live Chat Icon For mobile
Live Chat Icon

How can I work around my menu shortcuts from showing up incorrectly when I use Ctrl+Number?

Platform: WinForms| Category: Menus

When you assign Ctrl1, Ctrl2 etc as shortcuts for menuitems they show up as Ctrl+D1, Ctrl+D2. This can be worked around by creating and adding the menuitem through code as demonstrated below:


[C#]
//Create the menuitem 
MenuItem mymenuItem =  new MenuItem();
//ShortCut
mymenuItem.Shortcut = System.Windows.Forms.Shortcut.Ctrl1;
//Add Event Handler for the menuitem
mymenuItem.Click +=new EventHandler(this.mymenuItem_Click);
//ShortCut Text to be displayed
mymenuItem.Text = 'My MenuItem' +'\t'+ 'Ctrl+1';
//hide shortcut
mymenuItem.ShowShortcut = false;
//Add it to the bottom of the first menu
this.mainMenu1.MenuItems[0].MenuItems.Add(mymenuItem);

[VB.NET]
’Create the menuitem 
Dim mymenuItem As MenuItem =  New MenuItem() 
’ShortCut
mymenuItem.Shortcut = System.Windows.Forms.Shortcut.Ctrl1
’Add Event Handler for the menuitem
mymenuItem.Click +=New EventHandler(Me.mymenuItem_Click)
’ShortCut Text to be displayed
mymenuItem.Text = 'My MenuItem' +'\t'+ 'Ctrl+1'
’hide shortcut
mymenuItem.ShowShortcut = False
’Add it to the bottom of the first menu
Me.mainMenu1.MenuItems(0).MenuItems.Add(mymenuItem)

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.