O'Reilly logo

Visual Basic 2005 Jumpstart by Wei-Meng Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Add a Menu and Toolbar

Let's now add a menu and toolbar to the form. In VB 2005, you can create professional looking Windows applications, complete with menus and toolbars that look like those used with Microsoft Office applications.

Creating a new Windows application

Figure 1-2. Creating a new Windows application

The development environment of Visual Studio 2005

Figure 1-3. The development environment of Visual Studio 2005

  1. In the Menus & Toolbars tab in Toolbox, shown in Figure 1-4, locate and then drag and drop the ToolStripContainer control onto the form. The ToolStripContainer control allows other controls (such as the ToolStrip control) to anchor in the four positions available (left, right, top, and bottom).

    The various controls under the Menus & Toolbars tab in Toolbox

    Figure 1-4. The various controls under the Menus & Toolbars tab in Toolbox

    In the ToolStripContainer Tasks menu, click on the "Dock Fill in Form" link (see Figure 1-5) to dock the ToolStripContainer control onto the form. This will cause the ToolStripContainer control to fill up the entire form and automatically resize itself when the form is resized.

    Filling the entire form with the ToolStripContainer control

    Figure 1-5. Filling the entire form with the ToolStripContainer control

  2. Now you'll add the application menu. Double-click on the MenuStrip control in the Toolbox to add it to the form. The MenuStrip control displays a standard list of drop-down menus at the top of a window. In the MenuStrip Tasks menu, click on the Insert Standard Items link to add a list of commonly used menu items to the control (see Figure 1-6).

    Your form should now look like the one shown in Figure 1-7.

    Now you'll add a toolbar to Form1. Select the MenuStrip control that you have just added by single-clicking on it. In the Toolbox, double click on the ToolStrip control (or drag and drop it) to add it to the form. This will add the ToolStrip control to the top of the ToolStripContainer control, thereby making it moveable. You use the ToolStrip control to display buttons for tasks users will commonly want to perform. Initially, the toolbar is blank. To add common toolbar items, click on the Insert Standard Items link in the ToolStrip Tasks menus. Your form should now look like Figure 1-8.

    Inserting standard menu items into the MenuStrip control

    Figure 1-6. Inserting standard menu items into the MenuStrip control

    The MenuStrip control

    Figure 1-7. The MenuStrip control

    The MenuStrip and ToolStrip controls

    Figure 1-8. The MenuStrip and ToolStrip controls

  3. To test the application, press F5. You will now be able to drag the ToolStrip control and anchor it in one of the four positions (see Figure 1-9).

Anchoring the ToolStrip control in various positions

Figure 1-9. Anchoring the ToolStrip control in various positions

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required