ToolStripMenuItem Konstruktoren
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Initialisiert eine neue Instanz der ToolStripMenuItem-Klasse.
Überlädt
| Name | Beschreibung |
|---|---|
| ToolStripMenuItem() |
Initialisiert eine neue Instanz der ToolStripMenuItem-Klasse. |
| ToolStripMenuItem(Image) |
Initialisiert eine neue Instanz der Klasse, in der ToolStripMenuItem die angegebene ImageKlasse angezeigt wird. |
| ToolStripMenuItem(String) |
Initialisiert eine neue Instanz der ToolStripMenuItem Klasse, die den angegebenen Text anzeigt. |
| ToolStripMenuItem(String, Image) |
Initialisiert eine neue Instanz der ToolStripMenuItem Klasse, die den angegebenen Text und das angegebene Bild anzeigt. |
| ToolStripMenuItem(String, Image, EventHandler) |
Initialisiert eine neue Instanz der ToolStripMenuItem Klasse, die den angegebenen Text und das angegebene Bild anzeigt und die angegebene Aktion ausführt, wenn auf sie ToolStripMenuItem geklickt wird. |
| ToolStripMenuItem(String, Image, ToolStripItem[]) |
Initialisiert eine neue Instanz der ToolStripMenuItem Klasse, die den angegebenen Text und das angegebene Bild anzeigt und die angegebene ToolStripItem Auflistung enthält. |
| ToolStripMenuItem(String, Image, EventHandler, String) |
Initialisiert eine neue Instanz der ToolStripMenuItem Klasse mit dem angegebenen Namen, der den angegebenen Text und das angegebene Bild anzeigt, mit dem die angegebene Aktion ausgeführt wird, wenn auf sie ToolStripMenuItem geklickt wird. |
| ToolStripMenuItem(String, Image, EventHandler, Keys) |
Initialisiert eine neue Instanz der ToolStripMenuItem Klasse, die den angegebenen Text und das angegebene Bild anzeigt, führt die angegebene Aktion aus, wenn auf die ToolStripMenuItem Schaltfläche geklickt wird, und zeigt die angegebenen Tastenkombinationen an. |
ToolStripMenuItem()
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
Initialisiert eine neue Instanz der ToolStripMenuItem-Klasse.
public:
ToolStripMenuItem();
public ToolStripMenuItem();
Public Sub New ()
Gilt für:
ToolStripMenuItem(Image)
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
Initialisiert eine neue Instanz der Klasse, in der ToolStripMenuItem die angegebene ImageKlasse angezeigt wird.
public:
ToolStripMenuItem(System::Drawing::Image ^ 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
Public Sub New (image As Image)
Parameter
Hinweise
Verwenden Sie den ToolStripMenuItem Konstruktor, um ein ToolStripMenuItem Bild am Rand neben dem Text anzuzeigen.
Gilt für:
ToolStripMenuItem(String)
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
Initialisiert eine neue Instanz der ToolStripMenuItem Klasse, die den angegebenen Text anzeigt.
public:
ToolStripMenuItem(System::String ^ text);
public ToolStripMenuItem(string text);
public ToolStripMenuItem(string? text);
new System.Windows.Forms.ToolStripMenuItem : string -> System.Windows.Forms.ToolStripMenuItem
Public Sub New (text As String)
Parameter
- text
- String
Der Text, der im Menüelement angezeigt werden soll.
Beispiele
Im folgenden Codebeispiel wird die Verwendung des ToolStripMenuItem Konstruktors veranschaulicht.
// 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
Hinweise
Verwenden Sie den ToolStripMenuItem Konstruktor, um einen ToolStripMenuItem mit dem angegebenen Namen zu erstellen.
Gilt für:
ToolStripMenuItem(String, Image)
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
Initialisiert eine neue Instanz der ToolStripMenuItem Klasse, die den angegebenen Text und das angegebene Bild anzeigt.
public:
ToolStripMenuItem(System::String ^ text, System::Drawing::Image ^ image);
public ToolStripMenuItem(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
Public Sub New (text As String, image As Image)
Parameter
- text
- String
Der Text, der im Menüelement angezeigt werden soll.
Hinweise
Verwenden Sie den ToolStripMenuItem Konstruktor, um einen ToolStripMenuItem mit dem angegebenen Namen und Bild zu erstellen.
Gilt für:
ToolStripMenuItem(String, Image, EventHandler)
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
Initialisiert eine neue Instanz der ToolStripMenuItem Klasse, die den angegebenen Text und das angegebene Bild anzeigt und die angegebene Aktion ausführt, wenn auf sie ToolStripMenuItem geklickt wird.
public:
ToolStripMenuItem(System::String ^ text, System::Drawing::Image ^ image, EventHandler ^ onClick);
public ToolStripMenuItem(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
Public Sub New (text As String, image As Image, onClick As EventHandler)
Parameter
- text
- String
Der Text, der im Menüelement angezeigt werden soll.
- onClick
- EventHandler
Ein Ereignishandler, der das Click Ereignis auslöst, wenn auf das Steuerelement geklickt wird.
Beispiele
Im folgenden Codebeispiel wird die Verwendung des ToolStripMenuItem Konstruktors veranschaulicht.
// 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
Hinweise
Verwenden Sie zum ToolStripMenuItem Erstellen eines ToolStripMenuItem Elements, das sowohl Text als auch ein Bild anzeigt und die angegebene Aktion ausführt, wenn auf die ToolStripMenuItem Schaltfläche geklickt wird.
Gilt für:
ToolStripMenuItem(String, Image, ToolStripItem[])
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
Initialisiert eine neue Instanz der ToolStripMenuItem Klasse, die den angegebenen Text und das angegebene Bild anzeigt und die angegebene ToolStripItem Auflistung enthält.
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);
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
Public Sub New (text As String, image As Image, ParamArray dropDownItems As ToolStripItem())
Parameter
- text
- String
Der Text, der im Menüelement angezeigt werden soll.
- dropDownItems
- ToolStripItem[]
Die Menüelemente, die angezeigt werden sollen, wenn auf das Steuerelement geklickt wird.
Hinweise
Verwenden Sie den ToolStripMenuItem Konstruktor, um einen ToolStripMenuItem Text und ein Bild zu erstellen, das die angegebene ToolStripItem Auflistung enthält.
Gilt für:
ToolStripMenuItem(String, Image, EventHandler, String)
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
Initialisiert eine neue Instanz der ToolStripMenuItem Klasse mit dem angegebenen Namen, der den angegebenen Text und das angegebene Bild anzeigt, mit dem die angegebene Aktion ausgeführt wird, wenn auf sie ToolStripMenuItem geklickt wird.
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);
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
Public Sub New (text As String, image As Image, onClick As EventHandler, name As String)
Parameter
- text
- String
Der Text, der im Menüelement angezeigt werden soll.
- onClick
- EventHandler
Ein Ereignishandler, der das Click Ereignis auslöst, wenn auf das Steuerelement geklickt wird.
- name
- String
Der Name des Menüelements.
Beispiele
Im folgenden Codebeispiel wird die Verwendung des ToolStripMenuItem Konstruktors veranschaulicht.
// 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
Gilt für:
ToolStripMenuItem(String, Image, EventHandler, Keys)
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
- Quelle:
- ToolStripMenuItem.cs
Initialisiert eine neue Instanz der ToolStripMenuItem Klasse, die den angegebenen Text und das angegebene Bild anzeigt, führt die angegebene Aktion aus, wenn auf die ToolStripMenuItem Schaltfläche geklickt wird, und zeigt die angegebenen Tastenkombinationen an.
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);
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
Public Sub New (text As String, image As Image, onClick As EventHandler, shortcutKeys As Keys)
Parameter
- text
- String
Der Text, der im Menüelement angezeigt werden soll.
- onClick
- EventHandler
Ein Ereignishandler, der das Click Ereignis auslöst, wenn auf das Steuerelement geklickt wird.
- shortcutKeys
- Keys
Einer der Werte, die Keys die Tastenkombination für die ToolStripMenuItem.
Hinweise
Verwenden Sie den ToolStripMenuItem Konstruktor, um einen ToolStripMenuItem Text und ein Bild anzuzeigen, führt die angegebene Aktion aus, wenn darauf geklickt wird, und weist die angegebene Tastenkombination auf.