1.2. 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.

Figure 1-2. Creating a new Windows application

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).

    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.

    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.

    Smart Tasks Menu

    When you need to configure a control in VB6, you normally use its Properties window to do so. However, a properties list can be quite long, making it difficult for a beginner to find a particular property. In Visual Studio 2005, the Smart Tasks menu simplifies the task of configuring controls by listing several commonly used properties and wizards in the new Smart Tasks menu. You can display the Smart Tasks menu for any control by clicking the arrow at the top-right corner of the control.

    Figure 1-5 shows the ToolStripContainer Tasks menu. Using this Smart Tasks menu, you can set the visibility of the Panel (Top, Bottom, Left, and Right) as well as cause the control to fill up the form.

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

    Figure 1-7. The MenuStrip control

    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).

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

Visual Basic 2005 Jumpstart 2005
Visual Basic 2005 Jumpstart
ISBN: 059610071X
EAN: 2147483647
Year: 2005
Pages: 86
Authors: Wei-Meng Lee

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net