MenuItem.Select 事件

定义

当用户将指针放在菜单项上时发生。Occurs when the user places the pointer over a menu item.

public:
 event EventHandler ^ Select;
public event EventHandler Select;
member this.Select : EventHandler 
Public Custom Event Select As EventHandler 

示例

下面的代码示例演示如何使用 MenuItem 类的 Select 事件将帮助文本分配给 StatusBar 控件的 StatusBarPanelThe following code example demonstrates how to use the Select event of the MenuItem class to assign help text to a StatusBarPanel of a StatusBar control. 此示例要求将 MenuItem 名为 menuOpenmenuSavemenuExit 的对象添加到窗体上的 MainMenu 控件中。This example requires that MenuItem objects named menuOpen, menuSave, and menuExit are added to a MainMenu control on a form. 该示例还要求将名为 statusBar1 StatusBar 控件添加到窗体中。The example also requires that a StatusBar control, named statusBar1 has been added to the form. StatusBar 控件应包含一个 StatusBarPanelThe StatusBar control should contain a StatusBarPanel.

private:
   void MenuSelected( Object^ sender, System::EventArgs^ /*e*/ )
   {
      if ( sender == menuOpen )
            statusBar1->Panels[ 0 ]->Text = "Opens a file to edit";
      else
      if ( sender == menuSave )
            statusBar1->Panels[ 0 ]->Text = "Saves the current file";
      else
      if ( sender == menuExit )
            statusBar1->Panels[ 0 ]->Text = "Exits the application";
      else
            statusBar1->Panels[ 0 ]->Text = "Ready";
   }
private void MenuSelected(object sender, System.EventArgs e)
{
   if (sender == menuOpen)
      statusBar1.Panels[0].Text = "Opens a file to edit";
   else if(sender == menuSave)
      statusBar1.Panels[0].Text = "Saves the current file";
   else if(sender == menuExit)
      statusBar1.Panels[0].Text = "Exits the application";
   else
      statusBar1.Panels[0].Text = "Ready";
}
Private Sub MenuSelected(ByVal sender As Object, ByVal e As System.EventArgs) _
                     Handles menuOpen.Select, menuExit.Select, menuSave.Select
   If sender Is menuOpen Then
      StatusBar1.Panels(0).Text = "Opens a file to edit"
   Else
      If sender Is menuSave Then
         StatusBar1.Panels(0).Text = "Saves the current file"
      Else
         If sender Is menuExit Then
            StatusBar1.Panels(0).Text = "Exits the application"
         Else
            StatusBar1.Panels(0).Text = "Ready"
         End If
      End If
   End If
End Sub

注解

当用户将鼠标指针放在菜单项上时,通常会引发此事件。This event is typically raised when the user places the mouse pointer over the menu item. 用户通过使用键盘滚动到菜单项来突出显示菜单项时,还可能会引发事件。The event can also be raised when the user highlights a menu item using the keyboard by scrolling to the menu item with the arrow keys. 可以使用此事件在应用程序状态栏中显示与此菜单项相关的详细帮助字符串。You can use this event to display a detailed help string pertaining to this menu item in an application's status bar. 有关处理事件的详细信息,请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.

备注

如果 MenuItemMenuItems 属性包含任何项,则不会引发此事件。If the MenuItems property for the MenuItem contains any items, this event is not raised. 父菜单项不会引发此事件。This event is not raised for parent menu items.

适用于

另请参阅