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?
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.
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.
The Items property is used to add and work with items in a ContextMenuStrip.
ContextMenuStrip replaces ContextMenu. You can associate a ContextMenuStrip with any control, and a right mouse click automatically displays the shortcut menu.
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(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With