Udostępnij za pośrednictwem


How to: Add Buttons to a ToolBar Control Using the Designer

Note

The ToolStrip control replaces and adds functionality to the ToolBar control; however, the ToolBar control is retained for both backward compatibility and future use, if you choose.

An integral part of the ToolBar control is the buttons you add to it. These can be used to provide easy access to menu commands or, alternately, they can be placed in another area of the user interface of your application to expose commands to your users that are not available in the menu structure.

The following procedure requires a Windows Application project with a form containing a ToolBar control. For information about setting up such a project, see How to: Create a Windows Application Project and How to: Add Controls to Windows Forms.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To add buttons at design time

  1. Select the ToolBar control.

  2. In the Properties window, click the Buttons property to select it and click the Ellipsis (VisualStudioEllipsesButton screenshot) button to open the ToolBarButton Collection Editor.

  3. Use the Add and Remove buttons to add and remove buttons from the ToolBar control.

  4. Configure the properties of the individual buttons in the Properties window that appears in the pane on the right side of the editor. The following table shows some important properties to consider.

    Property

    Description

    DropDownMenu

    Sets the menu to be displayed in the drop-down toolbar button. The toolbar button's Style property must be set to DropDownButton. This property takes an instance of the ContextMenu class as a reference.

    PartialPush

    Sets whether a toggle-style toolbar button is partially pushed. The toolbar button's Style property must be set to ToggleButton.

    Pushed

    Sets whether a toggle-style toolbar button is currently in the pushed state. The toolbar button's Style property must be set to ToggleButton or PushButton.

    Style

    Sets the style of the toolbar button. Must be one of the values in the ToolBarButtonStyle enumeration.

    Text

    The text string displayed by the button.

    ToolTipText

    The text that appears as a ToolTip for the button.

  5. Click OK to close the dialog box and create the panels you specified.

See Also

Tasks

How to: Define an Icon for a ToolBar Button

How to: Trigger Menu Events for Toolbar Buttons

Reference

ToolBar

ToolBar Control Overview (Windows Forms)

Other Resources

ToolBar Control (Windows Forms)