共用方式為


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 事件,將解說文字指派給 StatusBarPanel 控制項的 StatusBar 。 這個範例會 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) 方法。

適用於