ToolStripDropDownMenu (Clase) (System.Windows.Forms)

Cambiar vista:
Sin script
Biblioteca de clases de .NET Framework
ToolStripDropDownMenu (Clase)

Actualización: noviembre 2007

Proporciona la funcionalidad básica para el control ContextMenuStrip. Aunque los controles ToolStripDropDownMenu y ToolStripDropDown reemplazan y agregan funcionalidad al control Menu de versiones anteriores, se conserva Menu a efectos de compatibilidad con versiones anteriores y uso futuro, en su caso.

Espacio de nombres:  System.Windows.Forms
Ensamblado:  System.Windows.Forms (en System.Windows.Forms.dll)
Sintaxis

Visual Basic (Declaración)
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class ToolStripDropDownMenu _
	Inherits ToolStripDropDown
Visual Basic (Uso)
Dim instance As ToolStripDropDownMenu
C#
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class ToolStripDropDownMenu : ToolStripDropDown
Visual C++
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[ComVisibleAttribute(true)]
public ref class ToolStripDropDownMenu : public ToolStripDropDown
J#
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
/** @attribute ComVisibleAttribute(true) */
public class ToolStripDropDownMenu extends ToolStripDropDown
JScript
public class ToolStripDropDownMenu extends ToolStripDropDown
Comentarios

ToolStripDropDownMenu es la clase base para ContextMenuStrip, proporcionando las propiedades y los métodos de pintado y diseño necesarios. Las propiedades de esta clase que probablemente más va a utilizar directamente son ShowCheckMargin y ShowImageMargin, que determinan si el menú contextual podrá mostrar una marca de verificación, una imagen o ambas.

Ejemplos

En el ejemplo de código siguiente se muestra cómo crear e inicializar un control ContextMenuStrip estableciendo los márgenes de comprobación y de imagen. Para obtener una lista de código completa, vea Cómo: Habilitar los márgenes de comprobación y de imagen en los controles ContextMenuStrip.

Visual Basic
Public Sub New()
   ' Size the form to show three wide menu items.
   Me.Width = 500
   Me.Text = "ToolStripContextMenuStrip: Image and Check Margins"

   ' Create a new MenuStrip control.
   Dim ms As New MenuStrip()

   ' Create the ToolStripMenuItems for the MenuStrip control.
   Dim bothMargins As New ToolStripMenuItem("BothMargins")
   Dim imageMarginOnly As New ToolStripMenuItem("ImageMargin")
   Dim checkMarginOnly As New ToolStripMenuItem("CheckMargin")
   Dim noMargins As New ToolStripMenuItem("NoMargins")

   ' Customize the DropDowns menus.
   ' This ToolStripMenuItem has an image margin 
   ' and a check margin.
   bothMargins.DropDown = CreateCheckImageContextMenuStrip()
   CType(bothMargins.DropDown, ContextMenuStrip).ShowImageMargin = True
   CType(bothMargins.DropDown, ContextMenuStrip).ShowCheckMargin = True

   ' This ToolStripMenuItem has only an image margin.
   imageMarginOnly.DropDown = CreateCheckImageContextMenuStrip()
   CType(imageMarginOnly.DropDown, ContextMenuStrip).ShowImageMargin = True
   CType(imageMarginOnly.DropDown, ContextMenuStrip).ShowCheckMargin = False

   ' This ToolStripMenuItem has only a check margin.
   checkMarginOnly.DropDown = CreateCheckImageContextMenuStrip()
   CType(checkMarginOnly.DropDown, ContextMenuStrip).ShowImageMargin = False
   CType(checkMarginOnly.DropDown, ContextMenuStrip).ShowCheckMargin = True

   ' This ToolStripMenuItem has no image and no check margin.
   noMargins.DropDown = CreateCheckImageContextMenuStrip()
   CType(noMargins.DropDown, ContextMenuStrip).ShowImageMargin = False
   CType(noMargins.DropDown, ContextMenuStrip).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.
   Me.Controls.Add(ms)
 End Sub


C#
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);
}


Jerarquía de herencia

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
Seguridad para subprocesos

Todos los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.
Plataformas

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

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.
Información de versión

.NET Framework

Compatible con: 3.5, 3.0, 2.0
Vea también

Referencia

Otros recursos