Share via


How to: Add Toolbars to a Windows Forms Application

You can easily add a toolbar to your application by adding a ToolStrip control and then adding buttons to the toolbar. You can add individual ToolStripButton controls, or you can select from a group of controls, such as the ToolStripTextBox control. You can easily add a set of standard toolbar buttons to the toolbar by using the ToolStrip Tasks pane. This task pane lets you insert seven standard buttons onto the toolbar, as shown in the following illustration.

Accessing the ToolStrip Tasks pane

Toolstrip Tasks

To add a set of standard toolbar button

  1. On the File menu, click New Project.

    The New Project dialog box appears.

  2. Click Windows Forms Application and then click OK.

  3. Drag a ToolStrip control from the Toolbox to the form.

    toolStrip1 appears in the component tray, and a toolbar is added to the top of the form.

  4. Add a TextBox control to the form and leave the default name of textBox1.

  5. Click the TextBox control, and then change the following properties in the Properties window:

    Property

    Value

    Size

    260, 20

    Text

    This is a simple test

  6. Click the ToolStrip control, click the smart task arrow at the upper-right corner of the control, and then click Insert Standard Items.

    Seven standard buttons (New, Open, Save, Print, Cut, Copy, Paste, and Help) become visible on the toolbar.

  7. Double-click the CutToolStripButton control to add the default Click event handler, and add the following code. This code cuts the selected text in TextBox1 and copies it to the Clipboard.

    this.textBox1.Cut();
    
  8. Press F5 to run the code.

  9. When the form appears, select a word in the text box, and then click the Cut button (that has a scissor icon).

  10. Verify that the selected text has been removed from the text box.

    Note

    You must add code to the Click event handlers for the remaining buttons on the toolbar to get additional functionality.

See Also

Concepts

Designing a User Interface in Visual C#

Other Resources

Creating a Custom UI

Visual C# Guided Tour