Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
ToolStripMenuItem Class

Represents a selectable option displayed on a MenuStrip or ContextMenuStrip. Although ToolStripMenuItem replaces and adds functionality to the MenuItem control of previous versions, MenuItem is retained for both backward compatibility and future use if you choose.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Declaration)
<ToolStripItemDesignerAvailabilityAttribute(ToolStripItemDesignerAvailability.None Or ToolStripItemDesignerAvailability.MenuStrip Or ToolStripItemDesignerAvailability.ContextMenuStrip)> _
Public Class ToolStripMenuItem _
    Inherits ToolStripDropDownItem
Visual Basic (Usage)
Dim instance As ToolStripMenuItem
C#
[ToolStripItemDesignerAvailabilityAttribute(ToolStripItemDesignerAvailability.None|ToolStripItemDesignerAvailability.MenuStrip|ToolStripItemDesignerAvailability.ContextMenuStrip)]
public class ToolStripMenuItem : ToolStripDropDownItem
Visual C++
[ToolStripItemDesignerAvailabilityAttribute(ToolStripItemDesignerAvailability::None|ToolStripItemDesignerAvailability::MenuStrip|ToolStripItemDesignerAvailability::ContextMenuStrip)]
public ref class ToolStripMenuItem : public ToolStripDropDownItem
JScript
public class ToolStripMenuItem extends ToolStripDropDownItem

ToolStripMenuItem is a ToolStripDropDownItem that works with ToolStripDropDownMenu and ContextMenuStrip to handle the special highlighting, layout, and column arrangement for menus.

In order for a ToolStripMenuItem to be displayed, you must add it to a MenuStrip or ContextMenuStrip.

The ToolStripMenuItem class provides properties that enable you to configure the appearance and functionality of a menu item. To display a check mark next to a menu item, use the Checked property. Use this feature to identify a menu item that is selected in a list of mutually exclusive menu items. For example, if you have a set of menu items for setting the color of text in a TextBox control, use the Checked property to identify which color is currently selected. Use the ShortcutKeys property to define a keyboard combination that can be pressed to select the menu item.

The following code example adds a ShortcutKeyDisplayString to the specified menu items of a ContextMenuStrip. This code example is part of a larger example available in the ToolStripManager class overview.

Visual Basic
' Distinguish the merged items by setting the shortcut display string.
Dim tsmi As ToolStripMenuItem
For Each tsmi In  cmsItemsToMerge.Items
   tsmi.ShortcutKeyDisplayString = "Merged Item"
Next tsmi

C#
// Distinguish the merged items by setting the shortcut display string.
foreach (ToolStripMenuItem tsmi in cmsItemsToMerge.Items)
{
    tsmi.ShortcutKeyDisplayString = "Merged Item";
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker