Export (0) Print
Expand All

ToolStripDropDownMenu Class

Provides basic functionality for the ContextMenuStrip control. Although ToolStripDropDownMenu and ToolStripDropDown replace and add functionality to the Menu control of previous versions, Menu 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)

[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public class ToolStripDropDownMenu : ToolStripDropDown
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class ToolStripDropDownMenu extends ToolStripDropDown
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class ToolStripDropDownMenu extends ToolStripDropDown
Not applicable.

ToolStripDropDownMenu is the base class for ContextMenuStrip, providing necessary painting and layout properties and methods. The properties of this class that you are most likely to use directly are the ShowCheckMargin and ShowImageMargin properties, which determine whether the shortcut menu will be able to display a check mark, an image, or both.

The following code example demonstrates how to create and initialize a ContextMenuStrip control by setting the check and image margins. For a full code listing, see How to: Enable Check Margins and Image Margins in ContextMenuStrip Controls.

public Form5()
{
    // Size the form to show three wide menu items.
    this.Width = 500;
    this.Text = "ToolStripContextMenuStrip: Image and Check Margins";

    // Create a new MenuStrip control.
    MenuStrip ms = new MenuStrip();

    // Create the ToolStripMenuItems for the MenuStrip control.
    ToolStripMenuItem bothMargins = new ToolStripMenuItem("BothMargins");
    ToolStripMenuItem imageMarginOnly = new ToolStripMenuItem("ImageMargin");
    ToolStripMenuItem checkMarginOnly = new ToolStripMenuItem("CheckMargin");
    ToolStripMenuItem noMargins = new ToolStripMenuItem("NoMargins");

    // Customize the DropDowns menus.
    // This ToolStripMenuItem has an image margin 
    // and a check margin.
    bothMargins.DropDown = CreateCheckImageContextMenuStrip();
    ((ContextMenuStrip)bothMargins.DropDown).ShowImageMargin = true;
    ((ContextMenuStrip)bothMargins.DropDown).ShowCheckMargin = true;

    // This ToolStripMenuItem has only an image margin.
    imageMarginOnly.DropDown = CreateCheckImageContextMenuStrip();
    ((ContextMenuStrip)imageMarginOnly.DropDown).ShowImageMargin = true;
    ((ContextMenuStrip)imageMarginOnly.DropDown).ShowCheckMargin = false;

    // This ToolStripMenuItem has only a check margin.
    checkMarginOnly.DropDown = CreateCheckImageContextMenuStrip();
    ((ContextMenuStrip)checkMarginOnly.DropDown).ShowImageMargin = false;
    ((ContextMenuStrip)checkMarginOnly.DropDown).ShowCheckMargin = true;

    // This ToolStripMenuItem has no image and no check margin.
    noMargins.DropDown = CreateCheckImageContextMenuStrip();
    ((ContextMenuStrip)noMargins.DropDown).ShowImageMargin = false;
    ((ContextMenuStrip)noMargins.DropDown).ShowCheckMargin = false;

    // Populate the MenuStrip control with the ToolStripMenuItems.
    ms.Items.Add(bothMargins);
    ms.Items.Add(imageMarginOnly);
    ms.Items.Add(checkMarginOnly);
    ms.Items.Add(noMargins);

    // Dock the MenuStrip control to the top of the form.
    ms.Dock = DockStyle.Top;

    // Add the MenuStrip control to the controls collection last.
    // This is important for correct placement in the z-order.
    this.Controls.Add(ms);
}

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ScrollableControl
           System.Windows.Forms.ToolStrip
             System.Windows.Forms.ToolStripDropDown
              System.Windows.Forms.ToolStripDropDownMenu
                 System.Windows.Forms.ContextMenuStrip

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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft