ToolBarButton.DropDownMenu プロパティ

定義

ドロップダウン ツール バー ボタンに表示されるメニューを取得または設定します。Gets or sets the menu to be displayed in the drop-down toolbar button.

public:
 property System::Windows::Forms::Menu ^ DropDownMenu { System::Windows::Forms::Menu ^ get(); void set(System::Windows::Forms::Menu ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.ReferenceConverter))]
public System.Windows.Forms.Menu DropDownMenu { get; set; }
member this.DropDownMenu : System.Windows.Forms.Menu with get, set
Public Property DropDownMenu As Menu

プロパティ値

ドロップダウン ツール バー ボタンに表示される ContextMenuA ContextMenu to be displayed in the drop-down toolbar button. 既定値は、null です。The default is null.

属性

例外

割り当てられたオブジェクトが ContextMenu ではありません。The assigned object is not a ContextMenu.

次のコード例ではToolBar 、3 ToolBarButtonつのコントロールを作成し、そのボタンをツールバーに割り当てて、ボタンの共通プロパティをいくつか設定します。The following code example creates a ToolBar and three ToolBarButton controls, assigns the buttons to the toolbar, and sets some of the buttons' common properties. ImageListこのコードでは、、 ToolTip 、およびFormが作成され、に少なくともImage 1 つのImageListが割り当てられている必要があります。This code requires that an ImageList, ToolTip and a Form have been created and the ImageList has at least one Image assigned to it.

public:
   void InitializeMyToolBar()
   {
      // Create the ToolBar, ToolBarButton controls, and menus.
      ToolBarButton^ toolBarButton1 = gcnew ToolBarButton( "Open" );
      ToolBarButton^ toolBarButton2 = gcnew ToolBarButton;
      ToolBarButton^ toolBarButton3 = gcnew ToolBarButton;
      ToolBar^ toolBar1 = gcnew ToolBar;
      MenuItem^ menuItem1 = gcnew MenuItem( "Print" );
      array<MenuItem^>^ temp1 = {menuItem1};
      System::Windows::Forms::ContextMenu^ contextMenu1 =
         gcnew System::Windows::Forms::ContextMenu( temp1 );
      
      // Add the ToolBarButton controls to the ToolBar.
      toolBar1->Buttons->Add( toolBarButton1 );
      toolBar1->Buttons->Add( toolBarButton2 );
      toolBar1->Buttons->Add( toolBarButton3 );
      
      // Assign an ImageList to the ToolBar and show ToolTips.
      toolBar1->ImageList = imageList1;
      toolBar1->ShowToolTips = true;
      
      /* Assign ImageIndex, ContextMenu, Text, ToolTip, and 
         Style properties of the ToolBarButton controls. */
      toolBarButton2->Style = ToolBarButtonStyle::Separator;
      toolBarButton3->Text = "Print";
      toolBarButton3->Style = ToolBarButtonStyle::DropDownButton;
      toolBarButton3->ToolTipText = "Print";
      toolBarButton3->ImageIndex = 0;
      toolBarButton3->DropDownMenu = contextMenu1;
      
      // Add the ToolBar to a form.
      Controls->Add( toolBar1 );
   }
public void InitializeMyToolBar()
 {
    // Create the ToolBar, ToolBarButton controls, and menus.
    ToolBarButton toolBarButton1 = new ToolBarButton("Open");
    ToolBarButton toolBarButton2 = new ToolBarButton();
    ToolBarButton toolBarButton3 = new ToolBarButton();
    ToolBar toolBar1 = new ToolBar();
    MenuItem menuItem1 = new MenuItem("Print");
    ContextMenu contextMenu1 = new ContextMenu(new MenuItem[]{menuItem1});

     
    // Add the ToolBarButton controls to the ToolBar.
    toolBar1.Buttons.Add(toolBarButton1);
    toolBar1.Buttons.Add(toolBarButton2);
    toolBar1.Buttons.Add(toolBarButton3);
 
    // Assign an ImageList to the ToolBar and show ToolTips.
    toolBar1.ImageList = imageList1;
    toolBar1.ShowToolTips = true;
 
    /* Assign ImageIndex, ContextMenu, Text, ToolTip, and 
       Style properties of the ToolBarButton controls. */
    toolBarButton2.Style = ToolBarButtonStyle.Separator;
    toolBarButton3.Text = "Print";
    toolBarButton3.Style = ToolBarButtonStyle.DropDownButton;
    toolBarButton3.ToolTipText = "Print";
    toolBarButton3.ImageIndex = 0;
    toolBarButton3.DropDownMenu = contextMenu1;
 
    // Add the ToolBar to a form.
    Controls.Add(toolBar1);
 }
 
Public Sub InitializeMyToolBar()
    ' Create the ToolBar, ToolBarButton controls, and menus.
    Dim toolBarButton1 As New ToolBarButton("Open")
    Dim toolBarButton2 As New ToolBarButton()
    Dim toolBarButton3 As New ToolBarButton()
    Dim toolBar1 As New ToolBar()
Dim menuItem1 As New MenuItem("Print")
Dim contextMenu1 As New ContextMenu(New MenuItem(){menuItem1})
    
    ' Add the ToolBarButton controls to the ToolBar.
    toolBar1.Buttons.Add(toolBarButton1)
    toolBar1.Buttons.Add(toolBarButton2)
    toolBar1.Buttons.Add(toolBarButton3)
    
    ' Assign an ImageList to the ToolBar and show ToolTips.
    toolBar1.ImageList = imageList1
    toolBar1.ShowToolTips = True
    
    ' Assign ImageIndex, ContextMenu, Text, ToolTip, and
    ' Style properties of the ToolBarButton controls. 
    toolBarButton2.Style = ToolBarButtonStyle.Separator
    toolBarButton3.Text = "Print"
    toolBarButton3.Style = ToolBarButtonStyle.DropDownButton
    toolBarButton3.ToolTipText = "Print"
    toolBarButton3.ImageIndex = 0
    toolBarButton3.DropDownMenu = contextMenu1
    
    ' Add the ToolBar to a form.
    Controls.Add(toolBar1)
End Sub

注釈

ドロップダウンボタンをContextMenuクリックしたときに表示されるを指定できます。You can specify a ContextMenu to be displayed when the drop-down button is clicked. プロパティ値がにStyle ToolBarButtonStyle.DropDownButton設定されている場合を除き、このプロパティは使用されません。This property is not used unless the Style property value is set to ToolBarButtonStyle.DropDownButton.

注意

プロパティはMenu型として定義されていますが、 ContextMenu適切に表示するには、このプロパティを割り当てる必要があります。 DropDownMenuAlthough the DropDownMenu property is defined as a Menu type, you must assign it a ContextMenu for it to display properly. 独自MenuItemの派生クラスを作成する場合は、そのオブジェクトContextMenuをに割り当て、をDropDownMenuプロパティContextMenuに割り当てる必要があります。If you are creating your own MenuItem derived class you must assign that object to a ContextMenu and assign the ContextMenu to the DropDownMenu property.

適用対象

こちらもご覧ください