MenuItem.OnSelect(EventArgs) 方法

定义

引发 Select 事件。

protected:
 virtual void OnSelect(EventArgs ^ e);
protected virtual void OnSelect (EventArgs e);
abstract member OnSelect : EventArgs -> unit
override this.OnSelect : EventArgs -> unit
Protected Overridable Sub OnSelect (e As EventArgs)

参数

e
EventArgs

包含事件数据的 EventArgs

示例

下面的代码示例演示如何使用 Select 类的 MenuItem 事件将帮助文本分配给控件的 StatusBarStatusBarPanel 此示例要求 MenuItem 将名为 menuOpenmenuSavemenuExit 的对象添加到窗体上的控件 MainMenu 中。 该示例还要求 StatusBar 已将名为 的 statusBar1 控件添加到窗体中。 控件 StatusBar 应包含 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

注解

引发事件时,将通过委托调用事件处理程序。 有关详细信息,请参阅 处理和引发事件

继承者说明

在派生类中重写 OnSelect(EventArgs) 时,请务必调用基类的 OnSelect(EventArgs) 方法。

适用于