ContextMenu.Popup イベントとは? わかりやすく解説

ContextMenu.Popup イベント

ショートカット メニュー表示される前に発生します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

解説解説
使用例使用例

ContextMenuPopup イベントイベント ハンドラ作成するコード例次に示します。このイベント ハンドラコードは、ショートカット メニュー表示しているコントロールpictureBox1 という名前の PictureBox コントロールtextBox1 という名前の TextBox コントロールのどちらであるかを判断します。どちらのコントロールContextMenuショートカット メニュー表示したに応じて適切な MenuItem オブジェクトContextMenu追加されます。この例では、フォーム内で定義されている contextMenu1 という名前の ContextMenu クラスインスタンスが既に存在する必要があります。またこの例では、TextBoxPictureBoxフォーム追加されており、これらのコントロールContextMenu プロパティcontextMenu1設定されている必要があります

Private Sub MyPopupEventHandler(sender As
 System.Object, e As System.EventArgs)
    ' Define the MenuItem objects to display for the TextBox.
    Dim menuItem1 As New
 MenuItem("&Copy")
    Dim menuItem2 As New
 MenuItem("&Find and Replace")
    ' Define the MenuItem object to display for the PictureBox.
    Dim menuItem3 As New
 MenuItem("C&hange Picture")
    
    ' Clear all previously added MenuItems.
    contextMenu1.MenuItems.Clear()
    
    If contextMenu1.SourceControl Is textBox1
 Then
        ' Add MenuItems to display for the TextBox.
        contextMenu1.MenuItems.Add(menuItem1)
        contextMenu1.MenuItems.Add(menuItem2)
    ElseIf contextMenu1.SourceControl Is pictureBox1
 Then
        ' Add the MenuItem to display for the PictureBox.
        contextMenu1.MenuItems.Add(menuItem3)
    End If
End Sub 'MyPopupEventHandler '
private void MyPopupEventHandler(System.Object
 sender, System.EventArgs e)
 {
    // Define the MenuItem objects to display for the TextBox.
    MenuItem menuItem1 = new MenuItem("&Copy");
    MenuItem menuItem2 = new MenuItem("&Find and Replace");
    // Define the MenuItem object to display for the PictureBox.
    MenuItem menuItem3 = new MenuItem("C&hange Picture");

    // Clear all previously added MenuItems.
    contextMenu1.MenuItems.Clear();
 
    if(contextMenu1.SourceControl == textBox1)
    {
       // Add MenuItems to display for the TextBox.
       contextMenu1.MenuItems.Add(menuItem1);
       contextMenu1.MenuItems.Add(menuItem2);
    }
    else if(contextMenu1.SourceControl == pictureBox1)
    {
       // Add the MenuItem to display for the PictureBox.
       contextMenu1.MenuItems.Add(menuItem3);
    }
 }
private:
   void MyPopupEventHandler( System::Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      // Define the MenuItem objects to display for the TextBox.
      MenuItem^ menuItem1 = gcnew MenuItem( "&Copy" );
      MenuItem^ menuItem2 = gcnew MenuItem( "&Find and Replace" );
      // Define the MenuItem object to display for the PictureBox.
      MenuItem^ menuItem3 = gcnew MenuItem( "C&hange Picture" );
      
      // Clear all previously added MenuItems.
      contextMenu1->MenuItems->Clear();

      if ( contextMenu1->SourceControl == textBox1 )
      {
         
         // Add MenuItems to display for the TextBox.
         contextMenu1->MenuItems->Add( menuItem1 );
         contextMenu1->MenuItems->Add( menuItem2 );
      }
      else if ( contextMenu1->SourceControl
 == pictureBox1 )
      {
         // Add the MenuItem to display for the PictureBox.
         contextMenu1->MenuItems->Add( menuItem3 );
      }
   }
private void MyPopupEventHandler(Object sender,
 EventArgs e)
{
    // Define the MenuItem objects to display for the TextBox.
    MenuItem menuItem1 = new MenuItem("&Copy");
    MenuItem menuItem2 = new MenuItem("&Find and Replace");

    // Define the MenuItem object to display for the PictureBox.
    MenuItem menuItem3 = new MenuItem("C&hange Picture");

    // Clear all previously added MenuItems.
    contextMenu1.get_MenuItems().Clear();
    if (contextMenu1.get_SourceControl().Equals(textBox1)) {
        // Add MenuItems to display for the TextBox.
        contextMenu1.get_MenuItems().Add(menuItem1);
        contextMenu1.get_MenuItems().Add(menuItem2);
    }
    else {
        if (contextMenu1.get_SourceControl().Equals(pictureBox1))
 {
            // Add the MenuItem to display for the PictureBox.
            contextMenu1.get_MenuItems().Add(menuItem3);
        }
    }
} //MyPopupEventHandler
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からContextMenu.Popup イベントを検索した結果を表示しています。
Weblioに収録されているすべての辞書からContextMenu.Popup イベントを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からContextMenu.Popup イベント を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

ContextMenu.Popup イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ContextMenu.Popup イベントのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS