Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the default menu item in a ContextMenuStrip?

Tags:

In my application I am using a popup menu item when right clicking an object. I dynamically build up this menu using code like this:

ContextMenuStrip menu = new ContextMenuStrip(); menu.Items.Add(new ToolStripMenuItem("Item1", aNiceImage, someFunction)); menu.Items.Add(new ToolStripMenuItem("Item2", alsoNiceImage, someOtherFunction)); 

Now I want to set one of these menu items in bold (as it is recommended by the Windows User Experience Guidelines) to indicate which action corresponds with double clicking the object.

How do I do this?

like image 279
Bart Gijssens Avatar asked Oct 24 '11 13:10

Bart Gijssens


People also ask

What are default menu items?

The default menu item for a menu is boldfaced. When the user double-clicks a submenu that contains a default item, the default item is selected, and the submenu is closed. You can use the DefaultItem property to indicate, the default action that is expected in a menu or shortcut menu.

What is the difference between MenuStrip and ContextMenuStrip?

MenuStrip is used to add menu items on the form (along the top edge). ContextMenuStrip is used to add items that appear when you right-click on a control.

Which property we have to set to use the ContextMenuStrip?

The Items property is used to add and work with items in a ContextMenuStrip.

Which of the following represents a shortcut menu a ContextMenuStrip B ContextMenuStrip C ContextMenuStrip D ContextMenuStrip?

ContextMenuStrip replaces ContextMenu. You can associate a ContextMenuStrip with any control, and a right mouse click automatically displays the shortcut menu.


1 Answers

use item.Font = new Font(item.Font, item.Font.Style | FontStyle.Bold) to make bold effect to the current font.

you can also auto select the default item as follows:

private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)  {   contextMenuStrip1.Items[3].Select(); } 
like image 193
Mohamed Abed Avatar answered Sep 28 '22 10:09

Mohamed Abed