Export (0) Print
Expand All

MenuItem.PerformSelect Method

Raises the Select event for this menu item.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public virtual void PerformSelect()

This method allows you to raise the Select event without passing any event information to the event handler.

In this example you programmatically select a menu item by using the PerformSelect method. First, you create a main menu (mainMenu1) and add to it two menu items, menuItem1 (File) and menuItem2 (Edit). You also use the Select event to send data to the event handler when a menu item is selected. Then you use the PerformSelect method to select the File menu item. When you start the application, the File menu item is selected, and a message box that contains the text "The File menu is selected." appears on the screen. The example requires that you have created a Form named Form1.

		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.
			// 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. 

			// Select the File menu item.

		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");		

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft