Export (0) Print
Expand All

ToolBarButton.DropDownMenu Property

Gets or sets the menu to be displayed in the drop-down toolbar button.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[TypeConverterAttribute(typeof(ReferenceConverter))]
public Menu DropDownMenu { get; set; }

Property Value

Type: System.Windows.Forms.Menu
A ContextMenu to be displayed in the drop-down toolbar button. The default is null.

ExceptionCondition
ArgumentException

The assigned object is not a ContextMenu.

You can specify a ContextMenu to be displayed when the drop-down button is clicked. This property is not used unless the Style property value is set to ToolBarButtonStyle.DropDownButton.

NoteNote

Although the DropDownMenu property is defined as a Menu type, you must assign it a ContextMenu for it to display properly. 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.

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. 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 = 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);
 }
 

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft