Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-add-enhancements-to-toolstripmenuitems.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

6.5 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Add Enhancements to ToolStripMenuItems 03/30/2017
csharp
vb
commands [Windows Forms], grouping on menus
check marks [Windows Forms], adding to menus
ToolStripMenuItems [Windows Forms], displaying access keys
menus [Windows Forms], grouping commands
menu items [Windows Forms], displaying shortcut keys
ToolStripMenuItems
separators [Windows Forms], displaying on menus
menu items [Windows Forms], showing separators
menu items [Windows Forms], adding check marks
ToolStripMenuItems [Windows Forms], adding check marks
menu items [Windows Forms], adding images
ToolStripSeparators [Windows Forms], displaying on MenuStrips
menu items [Windows Forms], displaying access keys
ToolStripMenuItems [Windows Forms], displaying shortcut keys
ToolStripMenuItems [Windows Forms], adding images
keyboard shortcuts [Windows Forms], displaying on menus
images [Windows Forms], adding to menus
ToolStripMenuItems [Windows Forms], showing separator bars
aa5f19bb-b545-4378-bfa6-36ba592f0d7c

How to: Add Enhancements to ToolStripMenuItems

You can enhance the usability of xref:System.Windows.Forms.MenuStrip and xref:System.Windows.Forms.ContextMenuStrip controls in the following ways:

  • Add check marks to designate whether a feature is turned on or off, such as whether a ruler is displayed along the margin of a word-processing application, or to indicate which file in a list of files is being displayed, such as on a Window menu.

  • Add images that visually represent menu commands.

  • Display shortcut keys to provide a keyboard alternative to the mouse for performing commands. For example, pressing CTRL+C performs the Copy command.

  • Display access keys to provide a keyboard alternative to the mouse for menu navigation. For example, pressing ALT+F chooses the File menu.

  • Show separator bars to group related commands and make menus more readable.

To display a check mark on a menu command

To display a check mark that changes state with each click

To add an image to a menu command

Note

The image margin can also show a check mark if you so choose. Also, you can set the xref:System.Windows.Forms.ToolStripMenuItem.Checked%2A property of the image to true, and the image will appear with a hatched border around it at run time.

To display a shortcut key for a menu command

To display custom shortcut keys for a menu command

To display an access key for a menu command

Note

Avoid defining duplicate access keys, such as defining ALT+F twice in the same menu system. The selection order of duplicate access keys cannot be guaranteed.

To display a separator bar between menu commands

  • After you define your xref:System.Windows.Forms.MenuStrip and the items it will contain, use the xref:System.Windows.Forms.ToolStripItemCollection.AddRange%2A or xref:System.Windows.Forms.ToolStripItemCollection.Add%2A method to add the menu commands and xref:System.Windows.Forms.ToolStripSeparator controls to the xref:System.Windows.Forms.MenuStrip in the order you want.

    ' This code adds a top-level File menu to the MenuStrip.  
    Me.menuStrip1.Items.Add(New ToolStripMenuItem() _  
    {Me.fileToolStripMenuItem})  
    
    ' This code adds the New and Open menu commands, a separator bar,
    ' and the Save and Exit menu commands to the top-level File menu,
    ' in that order.  
    Me.fileToolStripMenuItem.DropDownItems.AddRange(New _  
    ToolStripMenuItem() {Me.newToolStripMenuItem, _  
    Me.openToolStripMenuItem, Me.toolStripSeparator1, _  
    Me.saveToolStripMenuItem, Me.exitToolStripMenuItem})  
    
    // This code adds a top-level File menu to the MenuStrip.  
    this.menuStrip1.Items.Add(new ToolStripItem[]_  
    {this.fileToolStripMenuItem});  
    
    // This code adds the New and Open menu commands, a separator bar,
    // and the Save and Exit menu commands to the top-level File menu,
    // in that order.  
    this.fileToolStripMenuItem.DropDownItems.AddRange(new _  
    ToolStripItem[] {  
    this.newToolStripMenuItem,  
    this.openToolStripMenuItem,  
    this.toolStripSeparator1,  
    this.saveToolStripMenuItem,  
    this.exitToolStripMenuItem});  
    

See also