ToolStripMenuItem ToolStripMenuItem ToolStripMenuItem ToolStripMenuItem Constructors

Definición

Sobrecargas

ToolStripMenuItem() ToolStripMenuItem() ToolStripMenuItem()

Inicializa una nueva instancia de la clase ToolStripMenuItem.Initializes a new instance of the ToolStripMenuItem class.

ToolStripMenuItem(Image) ToolStripMenuItem(Image) ToolStripMenuItem(Image)

Inicializa una nueva instancia de la clase ToolStripMenuItem que muestra el Image especificado.Initializes a new instance of the ToolStripMenuItem class that displays the specified Image.

ToolStripMenuItem(String) ToolStripMenuItem(String) ToolStripMenuItem(String) ToolStripMenuItem(String)

Inicializa una nueva instancia de la clase ToolStripMenuItem que muestra el texto especificado.Initializes a new instance of the ToolStripMenuItem class that displays the specified text.

ToolStripMenuItem(String, Image) ToolStripMenuItem(String, Image) ToolStripMenuItem(String, Image)

Inicializa una nueva instancia de la clase ToolStripMenuItem que muestra la imagen y el texto especificados.Initializes a new instance of the ToolStripMenuItem class that displays the specified text and image.

ToolStripMenuItem(String, Image, EventHandler) ToolStripMenuItem(String, Image, EventHandler) ToolStripMenuItem(String, Image, EventHandler)

Inicializa una nueva instancia de la clase ToolStripMenuItem que muestra la imagen y el texto especificados, y realiza la acción especificada cuando se hace clic en ToolStripMenuItem.Initializes a new instance of the ToolStripMenuItem class that displays the specified text and image and that does the specified action when the ToolStripMenuItem is clicked.

ToolStripMenuItem(String, Image, ToolStripItem[]) ToolStripMenuItem(String, Image, ToolStripItem[]) ToolStripMenuItem(String, Image, ToolStripItem[])

Inicializa una nueva instancia de la clase ToolStripMenuItem que muestra la imagen y el texto especificados, y que contiene la colección ToolStripItem especificada.Initializes a new instance of the ToolStripMenuItem class that displays the specified text and image and that contains the specified ToolStripItem collection.

ToolStripMenuItem(String, Image, EventHandler, String) ToolStripMenuItem(String, Image, EventHandler, String) ToolStripMenuItem(String, Image, EventHandler, String)

Inicializa una nueva instancia de la clase ToolStripMenuItem con el nombre especificado que muestra la imagen y el texto especificados, y realiza la acción especificada cuando se hace clic en ToolStripMenuItem.Initializes a new instance of the ToolStripMenuItem class with the specified name that displays the specified text and image that does the specified action when the ToolStripMenuItem is clicked.

ToolStripMenuItem(String, Image, EventHandler, Keys) ToolStripMenuItem(String, Image, EventHandler, Keys) ToolStripMenuItem(String, Image, EventHandler, Keys)

Inicializa una nueva instancia de la clase ToolStripMenuItem con la imagen y el texto especificados, realiza la acción especificada cuando se hace clic en ToolStripMenuItem y muestra las teclas de método abreviado especificado.Initializes a new instance of the ToolStripMenuItem class that displays the specified text and image, does the specified action when the ToolStripMenuItem is clicked, and displays the specified shortcut keys.

ToolStripMenuItem() ToolStripMenuItem() ToolStripMenuItem()

Inicializa una nueva instancia de la clase ToolStripMenuItem.Initializes a new instance of the ToolStripMenuItem class.

public:
 ToolStripMenuItem();
public ToolStripMenuItem ();
Public Sub New ()

ToolStripMenuItem(Image) ToolStripMenuItem(Image) ToolStripMenuItem(Image)

Inicializa una nueva instancia de la clase ToolStripMenuItem que muestra el Image especificado.Initializes a new instance of the ToolStripMenuItem class that displays the specified Image.

public:
 ToolStripMenuItem(System::Drawing::Image ^ image);
public ToolStripMenuItem (System.Drawing.Image image);
new System.Windows.Forms.ToolStripMenuItem : System.Drawing.Image -> System.Windows.Forms.ToolStripMenuItem

Parámetros

image
Image Image Image Image

Image que se va a mostrar en el control.The Image to display on the control.

Comentarios

Use la ToolStripMenuItem constructor para crear un ToolStripMenuItem que muestra una imagen en el margen junto al texto.Use the ToolStripMenuItem constructor to create a ToolStripMenuItem that displays an image in the margin alongside the text.

ToolStripMenuItem(String) ToolStripMenuItem(String) ToolStripMenuItem(String) ToolStripMenuItem(String)

Inicializa una nueva instancia de la clase ToolStripMenuItem que muestra el texto especificado.Initializes a new instance of the ToolStripMenuItem class that displays the specified text.

public:
 ToolStripMenuItem(System::String ^ text);
public ToolStripMenuItem (string text);
new System.Windows.Forms.ToolStripMenuItem : string -> System.Windows.Forms.ToolStripMenuItem
Public Sub New (text As String)

Parámetros

text
String String String String

Texto que se va a mostrar en el elemento de menú.The text to display on the menu item.

Ejemplos

En el ejemplo de código siguiente se muestra un uso de la ToolStripMenuItem constructor.The following code example demonstrates a use of the ToolStripMenuItem constructor.

// Create a MenuStrip control with a new window.
MenuStrip ms = new MenuStrip();
ToolStripMenuItem windowMenu = new ToolStripMenuItem("Window");
ToolStripMenuItem windowNewMenu = new ToolStripMenuItem("New", null, new EventHandler(windowNewMenu_Click));
windowMenu.DropDownItems.Add(windowNewMenu);
((ToolStripDropDownMenu)(windowMenu.DropDown)).ShowImageMargin = false;
((ToolStripDropDownMenu)(windowMenu.DropDown)).ShowCheckMargin = true;

// Assign the ToolStripMenuItem that displays 
// the list of child forms.
ms.MdiWindowListItem = windowMenu;

// Add the window ToolStripMenuItem to the MenuStrip.
ms.Items.Add(windowMenu);

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

// The Form.MainMenuStrip property determines the merge target.
this.MainMenuStrip = ms;
' Create a MenuStrip control with a new window.
Dim ms As New MenuStrip()
Dim windowMenu As New ToolStripMenuItem("Window")
Dim windowNewMenu As New ToolStripMenuItem("New", Nothing, New EventHandler(AddressOf windowNewMenu_Click))
windowMenu.DropDownItems.Add(windowNewMenu)
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowImageMargin = False
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowCheckMargin = True

' Assign the ToolStripMenuItem that displays 
' the list of child forms.
ms.MdiWindowListItem = windowMenu

' Add the window ToolStripMenuItem to the MenuStrip.
ms.Items.Add(windowMenu)

' Dock the MenuStrip to the top of the form.
ms.Dock = DockStyle.Top

' The Form.MainMenuStrip property determines the merge target.
Me.MainMenuStrip = ms

Comentarios

Use la ToolStripMenuItem constructor para crear un ToolStripMenuItem con el nombre especificado.Use the ToolStripMenuItem constructor to create a ToolStripMenuItem with the specified name.

ToolStripMenuItem(String, Image) ToolStripMenuItem(String, Image) ToolStripMenuItem(String, Image)

Inicializa una nueva instancia de la clase ToolStripMenuItem que muestra la imagen y el texto especificados.Initializes a new instance of the ToolStripMenuItem class that displays the specified text and image.

public:
 ToolStripMenuItem(System::String ^ text, System::Drawing::Image ^ image);
public ToolStripMenuItem (string text, System.Drawing.Image image);
new System.Windows.Forms.ToolStripMenuItem : string * System.Drawing.Image -> System.Windows.Forms.ToolStripMenuItem

Parámetros

text
String String String String

Texto que se va a mostrar en el elemento de menú.The text to display on the menu item.

image
Image Image Image Image

Image que se va a mostrar en el control.The Image to display on the control.

Comentarios

Use la ToolStripMenuItem constructor para crear un ToolStripMenuItem con la imagen y el nombre especificado.Use the ToolStripMenuItem constructor to create a ToolStripMenuItem with the specified name and image.

ToolStripMenuItem(String, Image, EventHandler) ToolStripMenuItem(String, Image, EventHandler) ToolStripMenuItem(String, Image, EventHandler)

Inicializa una nueva instancia de la clase ToolStripMenuItem que muestra la imagen y el texto especificados, y realiza la acción especificada cuando se hace clic en ToolStripMenuItem.Initializes a new instance of the ToolStripMenuItem class that displays the specified text and image and that does the specified action when the ToolStripMenuItem is clicked.

public:
 ToolStripMenuItem(System::String ^ text, System::Drawing::Image ^ image, EventHandler ^ onClick);
public ToolStripMenuItem (string text, System.Drawing.Image image, EventHandler onClick);
new System.Windows.Forms.ToolStripMenuItem : string * System.Drawing.Image * EventHandler -> System.Windows.Forms.ToolStripMenuItem

Parámetros

text
String String String String

Texto que se va a mostrar en el elemento de menú.The text to display on the menu item.

image
Image Image Image Image

Image que se va a mostrar en el control.The Image to display on the control.

onClick
EventHandler EventHandler EventHandler EventHandler

Un controlador de eventos que provoca el evento Click cuando se hace clic en el control.An event handler that raises the Click event when the control is clicked.

Ejemplos

En el ejemplo de código siguiente se muestra un uso de la ToolStripMenuItem constructor.The following code example demonstrates a use of the ToolStripMenuItem constructor.

// Create a MenuStrip control with a new window.
MenuStrip ms = new MenuStrip();
ToolStripMenuItem windowMenu = new ToolStripMenuItem("Window");
ToolStripMenuItem windowNewMenu = new ToolStripMenuItem("New", null, new EventHandler(windowNewMenu_Click));
windowMenu.DropDownItems.Add(windowNewMenu);
((ToolStripDropDownMenu)(windowMenu.DropDown)).ShowImageMargin = false;
((ToolStripDropDownMenu)(windowMenu.DropDown)).ShowCheckMargin = true;

// Assign the ToolStripMenuItem that displays 
// the list of child forms.
ms.MdiWindowListItem = windowMenu;

// Add the window ToolStripMenuItem to the MenuStrip.
ms.Items.Add(windowMenu);

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

// The Form.MainMenuStrip property determines the merge target.
this.MainMenuStrip = ms;
' Create a MenuStrip control with a new window.
Dim ms As New MenuStrip()
Dim windowMenu As New ToolStripMenuItem("Window")
Dim windowNewMenu As New ToolStripMenuItem("New", Nothing, New EventHandler(AddressOf windowNewMenu_Click))
windowMenu.DropDownItems.Add(windowNewMenu)
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowImageMargin = False
CType(windowMenu.DropDown, ToolStripDropDownMenu).ShowCheckMargin = True

' Assign the ToolStripMenuItem that displays 
' the list of child forms.
ms.MdiWindowListItem = windowMenu

' Add the window ToolStripMenuItem to the MenuStrip.
ms.Items.Add(windowMenu)

' Dock the MenuStrip to the top of the form.
ms.Dock = DockStyle.Top

' The Form.MainMenuStrip property determines the merge target.
Me.MainMenuStrip = ms

Comentarios

Use la ToolStripMenuItem para crear un ToolStripMenuItem que muestra texto y una imagen y que realiza la acción especificada cuando el ToolStripMenuItem se hace clic en.Use the ToolStripMenuItem to create a ToolStripMenuItem that displays both text and an image and that does the specified action when the ToolStripMenuItem is clicked.

ToolStripMenuItem(String, Image, ToolStripItem[]) ToolStripMenuItem(String, Image, ToolStripItem[]) ToolStripMenuItem(String, Image, ToolStripItem[])

Inicializa una nueva instancia de la clase ToolStripMenuItem que muestra la imagen y el texto especificados, y que contiene la colección ToolStripItem especificada.Initializes a new instance of the ToolStripMenuItem class that displays the specified text and image and that contains the specified ToolStripItem collection.

public:
 ToolStripMenuItem(System::String ^ text, System::Drawing::Image ^ image, ... cli::array <System::Windows::Forms::ToolStripItem ^> ^ dropDownItems);
public ToolStripMenuItem (string text, System.Drawing.Image image, params System.Windows.Forms.ToolStripItem[] dropDownItems);
new System.Windows.Forms.ToolStripMenuItem : string * System.Drawing.Image * System.Windows.Forms.ToolStripItem[] -> System.Windows.Forms.ToolStripMenuItem

Parámetros

text
String String String String

Texto que se va a mostrar en el elemento de menú.The text to display on the menu item.

image
Image Image Image Image

Image que se va a mostrar en el control.The Image to display on the control.

dropDownItems
ToolStripItem[]

Elementos de menú que se mostrarán al hacer clic en el control.The menu items to display when the control is clicked.

Comentarios

Use la ToolStripMenuItem constructor para crear un ToolStripMenuItem que muestra una imagen y texto y que contiene el texto especificado ToolStripItem colección.Use the ToolStripMenuItem constructor to create a ToolStripMenuItem that displays text and an image and that contains the specified ToolStripItem collection.

ToolStripMenuItem(String, Image, EventHandler, String) ToolStripMenuItem(String, Image, EventHandler, String) ToolStripMenuItem(String, Image, EventHandler, String)

Inicializa una nueva instancia de la clase ToolStripMenuItem con el nombre especificado que muestra la imagen y el texto especificados, y realiza la acción especificada cuando se hace clic en ToolStripMenuItem.Initializes a new instance of the ToolStripMenuItem class with the specified name that displays the specified text and image that does the specified action when the ToolStripMenuItem is clicked.

public:
 ToolStripMenuItem(System::String ^ text, System::Drawing::Image ^ image, EventHandler ^ onClick, System::String ^ name);
public ToolStripMenuItem (string text, System.Drawing.Image image, EventHandler onClick, string name);
new System.Windows.Forms.ToolStripMenuItem : string * System.Drawing.Image * EventHandler * string -> System.Windows.Forms.ToolStripMenuItem

Parámetros

text
String String String String

Texto que se va a mostrar en el elemento de menú.The text to display on the menu item.

image
Image Image Image Image

Image que se va a mostrar en el control.The Image to display on the control.

onClick
EventHandler EventHandler EventHandler EventHandler

Un controlador de eventos que provoca el evento Click cuando se hace clic en el control.An event handler that raises the Click event when the control is clicked.

name
String String String String

Nombre del elemento de menú.The name of the menu item.

Ejemplos

En el ejemplo de código siguiente se muestra un uso de la ToolStripMenuItem constructor.The following code example demonstrates a use of the ToolStripMenuItem constructor.

// This code example demonstrates how to handle the Opening event.
// It also demonstrates dynamic item addition and dynamic 
// SourceControl determination with reuse.
class Form3 : Form
{
    // Declare the ContextMenuStrip control.
    private ContextMenuStrip fruitContextMenuStrip;

    public Form3()
    {
        // Create a new ContextMenuStrip control.
        fruitContextMenuStrip = new ContextMenuStrip();

        // Attach an event handler for the 
        // ContextMenuStrip control's Opening event.
        fruitContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(cms_Opening);

        // Create a new ToolStrip control.
        ToolStrip ts = new ToolStrip();

        // Create a ToolStripDropDownButton control and add it
        // to the ToolStrip control's Items collections.
        ToolStripDropDownButton fruitToolStripDropDownButton = new ToolStripDropDownButton("Fruit", null, null, "Fruit");
        ts.Items.Add(fruitToolStripDropDownButton);

        // Dock the ToolStrip control to the top of the form.
        ts.Dock = DockStyle.Top;

        // Assign the ContextMenuStrip control as the 
        // ToolStripDropDownButton control's DropDown menu.
        fruitToolStripDropDownButton.DropDown = fruitContextMenuStrip;

        // Create a new MenuStrip control and add a ToolStripMenuItem.
        MenuStrip ms = new MenuStrip();
        ToolStripMenuItem fruitToolStripMenuItem = new ToolStripMenuItem("Fruit", null, null, "Fruit");
        ms.Items.Add(fruitToolStripMenuItem);

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

        // Assign the MenuStrip control as the 
        // ToolStripMenuItem's DropDown menu.
        fruitToolStripMenuItem.DropDown = fruitContextMenuStrip;

        // Assign the ContextMenuStrip to the form's 
        // ContextMenuStrip property.
        this.ContextMenuStrip = fruitContextMenuStrip;

        // Add the ToolStrip control to the Controls collection.
        this.Controls.Add(ts);

        //Add a button to the form and assign its ContextMenuStrip.
        Button b = new Button();
        b.Location = new System.Drawing.Point(60, 60);
        this.Controls.Add(b);
        b.ContextMenuStrip = fruitContextMenuStrip;

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

    // This event handler is invoked when the ContextMenuStrip
    // control's Opening event is raised. It demonstrates
    // dynamic item addition and dynamic SourceControl 
    // determination with reuse.
    void cms_Opening(object sender, System.ComponentModel.CancelEventArgs e)
    {
        // Acquire references to the owning control and item.
        Control c = fruitContextMenuStrip.SourceControl as Control;
        ToolStripDropDownItem tsi = fruitContextMenuStrip.OwnerItem as ToolStripDropDownItem;

        // Clear the ContextMenuStrip control's Items collection.
        fruitContextMenuStrip.Items.Clear();

        // Check the source control first.
        if (c != null)
        {
            // Add custom item (Form)
            fruitContextMenuStrip.Items.Add("Source: " + c.GetType().ToString());
        }
        else if (tsi != null)
        {
            // Add custom item (ToolStripDropDownButton or ToolStripMenuItem)
            fruitContextMenuStrip.Items.Add("Source: " + tsi.GetType().ToString());
        }

        // Populate the ContextMenuStrip control with its default items.
        fruitContextMenuStrip.Items.Add("-");
        fruitContextMenuStrip.Items.Add("Apples");
        fruitContextMenuStrip.Items.Add("Oranges");
        fruitContextMenuStrip.Items.Add("Pears");

        // Set Cancel to false. 
        // It is optimized to true based on empty entry.
        e.Cancel = false;
    }
}
' This code example demonstrates how to handle the Opening event.
' It also demonstrates dynamic item addition and dynamic 
' SourceControl determination with reuse.
Class Form3
    Inherits Form

   ' Declare the ContextMenuStrip control.
   Private fruitContextMenuStrip As ContextMenuStrip
   
   
   Public Sub New()
      ' Create a new ContextMenuStrip control.
      fruitContextMenuStrip = New ContextMenuStrip()
      
      ' Attach an event handler for the 
      ' ContextMenuStrip control's Opening event.
      AddHandler fruitContextMenuStrip.Opening, AddressOf cms_Opening
      
      ' Create a new ToolStrip control.
      Dim ts As New ToolStrip()
      
      ' Create a ToolStripDropDownButton control and add it
      ' to the ToolStrip control's Items collections.
      Dim fruitToolStripDropDownButton As New ToolStripDropDownButton("Fruit", Nothing, Nothing, "Fruit")
      ts.Items.Add(fruitToolStripDropDownButton)
      
      ' Dock the ToolStrip control to the top of the form.
      ts.Dock = DockStyle.Top
      
      ' Assign the ContextMenuStrip control as the 
      ' ToolStripDropDownButton control's DropDown menu.
      fruitToolStripDropDownButton.DropDown = fruitContextMenuStrip
      
      ' Create a new MenuStrip control and add a ToolStripMenuItem.
      Dim ms As New MenuStrip()
      Dim fruitToolStripMenuItem As New ToolStripMenuItem("Fruit", Nothing, Nothing, "Fruit")
      ms.Items.Add(fruitToolStripMenuItem)
      
      ' Dock the MenuStrip control to the top of the form.
      ms.Dock = DockStyle.Top
      
      ' Assign the MenuStrip control as the 
      ' ToolStripMenuItem's DropDown menu.
      fruitToolStripMenuItem.DropDown = fruitContextMenuStrip
      
      ' Assign the ContextMenuStrip to the form's 
      ' ContextMenuStrip property.
      Me.ContextMenuStrip = fruitContextMenuStrip
      
      ' Add the ToolStrip control to the Controls collection.
        Me.Controls.Add(ts)

        'Add a button to the form and assign its ContextMenuStrip.
        Dim b As New Button()
        b.Location = New System.Drawing.Point(60, 60)
        Me.Controls.Add(b)
        b.ContextMenuStrip = fruitContextMenuStrip
      
      ' Add the MenuStrip control last.
      ' This is important for correct placement in the z-order.
      Me.Controls.Add(ms)
    End Sub
   
   ' This event handler is invoked when the ContextMenuStrip
   ' control's Opening event is raised. It demonstrates
   ' dynamic item addition and dynamic SourceControl 
   ' determination with reuse.
    Sub cms_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)

        ' Acquire references to the owning control and item.
        Dim c As Control = fruitContextMenuStrip.SourceControl
        Dim tsi As ToolStripDropDownItem = fruitContextMenuStrip.OwnerItem 

        ' Clear the ContextMenuStrip control's 
        ' Items collection.
        fruitContextMenuStrip.Items.Clear()

        ' Check the source control first.
        If (c IsNot Nothing) Then
            ' Add custom item (Form)
            fruitContextMenuStrip.Items.Add(("Source: " + c.GetType().ToString()))
        ElseIf (tsi IsNot Nothing) Then
            ' Add custom item (ToolStripDropDownButton or ToolStripMenuItem)
            fruitContextMenuStrip.Items.Add(("Source: " + tsi.GetType().ToString()))
        End If

        ' Populate the ContextMenuStrip control with its default items.
        fruitContextMenuStrip.Items.Add("-")
        fruitContextMenuStrip.Items.Add("Apples")
        fruitContextMenuStrip.Items.Add("Oranges")
        fruitContextMenuStrip.Items.Add("Pears")

        ' Set Cancel to false. 
        ' It is optimized to true based on empty entry.
        e.Cancel = False
    End Sub
End Class

ToolStripMenuItem(String, Image, EventHandler, Keys) ToolStripMenuItem(String, Image, EventHandler, Keys) ToolStripMenuItem(String, Image, EventHandler, Keys)

Inicializa una nueva instancia de la clase ToolStripMenuItem con la imagen y el texto especificados, realiza la acción especificada cuando se hace clic en ToolStripMenuItem y muestra las teclas de método abreviado especificado.Initializes a new instance of the ToolStripMenuItem class that displays the specified text and image, does the specified action when the ToolStripMenuItem is clicked, and displays the specified shortcut keys.

public:
 ToolStripMenuItem(System::String ^ text, System::Drawing::Image ^ image, EventHandler ^ onClick, System::Windows::Forms::Keys shortcutKeys);
public ToolStripMenuItem (string text, System.Drawing.Image image, EventHandler onClick, System.Windows.Forms.Keys shortcutKeys);
new System.Windows.Forms.ToolStripMenuItem : string * System.Drawing.Image * EventHandler * System.Windows.Forms.Keys -> System.Windows.Forms.ToolStripMenuItem

Parámetros

text
String String String String

Texto que se va a mostrar en el elemento de menú.The text to display on the menu item.

image
Image Image Image Image

Image que se va a mostrar en el control.The Image to display on the control.

onClick
EventHandler EventHandler EventHandler EventHandler

Un controlador de eventos que provoca el evento Click cuando se hace clic en el control.An event handler that raises the Click event when the control is clicked.

shortcutKeys
Keys Keys Keys Keys

Uno de los valores de Keys que representa la tecla de método abreviado para ToolStripMenuItem.One of the values of Keys that represents the shortcut key for the ToolStripMenuItem.

Comentarios

Use la ToolStripMenuItem constructor para crear un ToolStripMenuItem que muestra una imagen y texto, realiza la acción especificada cuando hace clic en y tiene la clave de acceso de directo especificado.Use the ToolStripMenuItem constructor to create a ToolStripMenuItem that displays text and an image, performs the specified action when clicked, and has the specified shortcut key.

Se aplica a