Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Löst das Select-Ereignis für dieses Menüelement aus.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Public Overridable Sub PerformSelect
'Usage
Dim instance As MenuItem
instance.PerformSelect
public virtual void PerformSelect ()
public:
virtual void PerformSelect ()
public void PerformSelect ()
public function PerformSelect ()
Hinweise
Mit dieser Methode können Sie das Select-Ereignis auslösen, ohne Ereignisinformationen an den Ereignishandler zu übergeben.
Beispiel
In diesem Beispiel wird die PerformSelect-Methode verwendet, um programmgesteuert ein Menüelement zu wählen. Zunächst wird ein Hauptmenü (mainMenu1) erstellt, und diesem Menü werden zwei Menüelemente, menuItem1 (File) und menuItem2 (Edit), hinzugefügt. Danach werden mithilfe des Select-Ereignisses Daten an den Ereignishandler gesendet, sobald ein Menüelement ausgewählt wurde. Und schließlich wird die PerformSelect-Methode verwendet, um das Menüelement File zu wählen. Wenn Sie die Anwendung starten, wird das Menüelement File gewählt, und es wird ein Meldungsfeld mit dem Text "The File menu is selected." angezeigt. Bei diesem Beispiel ist es erforderlich, dass zuvor ein Form mit dem Namen Form1 erstellt wurde.
Public Sub CreateMyMenu()
' Create a main menu object.
Dim mainMenu1 As New MainMenu()
' Create empty menu item objects.
Dim menuItem1 As New MenuItem()
Dim menuItem2 As New MenuItem()
' Set the caption of the menu items.
menuItem1.Text = "&File"
menuItem2.Text = "&Edit"
' Add the menu items to the main menu.
mainMenu1.MenuItems.Add(menuItem1)
mainMenu1.MenuItems.Add(menuItem2)
' Add functionality to the menu items.
AddHandler menuItem1.Select, AddressOf Me.menuItem1_Select
AddHandler menuItem2.Select, AddressOf Me.menuItem2_Select
' Assign mainMenu1 to the form.
Me.Menu = mainMenu1
' Select the File menu item.
menuItem1.PerformSelect()
End Sub 'CreateMyMenu
Private Sub menuItem1_Select(ByVal sender As Object, ByVal e As System.EventArgs)
MessageBox.Show("You selected the File menu.", "The Event Information")
End Sub 'menuItem1_Select
Private Sub menuItem2_Select(ByVal sender As Object, ByVal e As System.EventArgs)
MessageBox.Show("You selected the Edit menu.", "The Event Information")
End Sub 'menuItem2_Select
public void CreateMyMenu()
{
// Create a main menu object.
MainMenu mainMenu1 = new MainMenu();
// Create empty menu item objects.
MenuItem menuItem1 = new MenuItem();
MenuItem menuItem2 = new MenuItem();
// Set the caption of the menu items.
menuItem1.Text = "&File";
menuItem2.Text = "&Edit";
// Add the menu items to the main menu.
mainMenu1.MenuItems.Add(menuItem1);
mainMenu1.MenuItems.Add(menuItem2);
// Add functionality to the menu items.
menuItem1.Select += new System.EventHandler(this.menuItem1_Select);
menuItem2.Select += new System.EventHandler(this.menuItem2_Select);
// Assign mainMenu1 to the form.
this.Menu=mainMenu1;
// Select the File menu item.
menuItem1.PerformSelect();
}
private void menuItem1_Select(object sender, System.EventArgs e)
{
MessageBox.Show("You selected the File menu.","The Event Information");
}
private void menuItem2_Select(object sender, System.EventArgs e)
{
MessageBox.Show("You selected the Edit menu.","The Event Information");
}
public:
void CreateMyMenu()
{
// Create a main menu objects.
MainMenu^ mainMenu1 = gcnew MainMenu;
// Create empty menu item objects.
MenuItem^ menuItem1 = gcnew MenuItem;
MenuItem^ menuItem2 = gcnew MenuItem;
// Set the caption of the menu items.
menuItem1->Text = "&File";
menuItem2->Text = "&Edit";
// Add the menu items to the main menu.
mainMenu1->MenuItems->Add( menuItem1 );
mainMenu1->MenuItems->Add( menuItem2 );
// Add functionality to the menu items.
menuItem1->Select += gcnew System::EventHandler( this, &Form1::menuItem1_Select );
menuItem2->Select += gcnew System::EventHandler( this, &Form1::menuItem2_Select );
// Assign mainMenu1 to the form.
this->Menu = mainMenu1;
// Select the File menu item.
menuItem1->PerformSelect();
}
private:
void menuItem1_Select( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
MessageBox::Show( "You selected the File menu.", "The Event Information" );
}
void menuItem2_Select( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
MessageBox::Show( "You selected the Edit menu.", "The Event Information" );
}
/** @attribute STAThread()
*/
public void CreateMyMenu()
{
// Create a main menu object.
MainMenu mainMenu1 = new MainMenu();
// Create empty menu item objects.
MenuItem menuItem1 = new MenuItem();
MenuItem menuItem2 = new MenuItem();
// Set the caption of the menu items.
menuItem1.set_Text("&File");
menuItem2.set_Text("&Edit");
// Add the menu items to the main menu.
mainMenu1.get_MenuItems().Add(menuItem1);
mainMenu1.get_MenuItems().Add(menuItem2);
// Add functionality to the menu items.
menuItem1.add_Select(new System.EventHandler(this.menuItem1_Select));
menuItem2.add_Select(new System.EventHandler(this.menuItem2_Select));
// Assign mainMenu1 to the form.
this.set_Menu(mainMenu1);
// Select the File menu item.
menuItem1.PerformSelect();
} //CreateMyMenu
private void menuItem1_Select(Object sender, System.EventArgs e)
{
MessageBox.Show("You selected the File menu.", "The Event Information");
} //menuItem1_Select
private void menuItem2_Select(Object sender, System.EventArgs e)
{
MessageBox.Show("You selected the Edit menu.", "The Event Information");
} //menuItem2_Select
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
MenuItem-Klasse
MenuItem-Member
System.Windows.Forms-Namespace
PerformClick