![]() |
|
|
Menus and ToolBars There are a few things that you can apply to your VB project to make it more user-friendly. Navigation, for example, should be considered the most important aspect of any program. Therefore, adding a menu bar to your project would enhance your user interface and also hide away all your sections in a neat bar. Menu Bars: VB makes it extremely easy to add a menu to your project. All you have to do is load the Menu Editor and then enter all your menus, menu items and submenus. This lesson will show you how to set up a basic menu and call different forms from each menu item. Click on Tools, then Menu Editor. Now create your first Menu option by entering the caption you want users to see and giving your item a name. Click on Next and you'll go down to the next position. Enter a second Menu option. You should have something that looks like the first image below. If you click on OK (but don't, yet), your Menu would like the second image:
In order to create a menu for each of the options (File, Options) above, we'll need to enter all the items under each option. While still on the Options option, click on Insert and enter a new item with the name: mnuExit and caption: Quit Program. Now click on the Right Arrow button. Repeat this step two more times. Use the names and captions below: Name: mnuLine Caption: - Name: mnuMsg Caption: Display Message When the Caption is set to "-" then a separator line appears on your menu Click on OK. The first image is how your editor should look like. The second is how your completed menu should look like:
To create submenus within your current menu items, enter your submenu items under a menu item and then click on the Right Arrow button so that it forms a third hierarchy. The next step is fairly simple, just click on each menu item (for example mnuExit) and you'll go into Code View. Now enter whatever command you want your program to execute when the user clicks on this menu item. Here's an example for the mnuExit item:
Private Sub mnuExit_Click() The command End exits the program.
Toolbars: A ToolBar is another thing that you can add to your project to make it look much more professional. If you want a toolbar with pictures, than there are two things that you need to do. 1. Set up the ToolBar 2. Set up an ImageList that will hold all your images To set up your ToolBar, you'll first need to add the ToolBar component to your ToolBox. Go to Project, then Components and put a check next t Microsoft Windows Common Controls 6.0. Click on OK. Now
click on the ToolBar icon We'll start by building our ImageList with all the images that we'll be using for our ToolBar. Right Click on the ImageList and click on Properties. You should get a new window. On the General tab choose 16x16 pixels for the size. On the Images tab, click Insert Picture and insert all the images that you want to use for your toolbar. For best results, make sure your images are as close to 16x16 pixels as possible. Now right click on your ToolBar and select Properties. Choose ImageList1 for the ImageList option and then switch to the Buttons tab. Click on Insert Button. Enter Button 1 for the caption (if you want to display text with each button) and 1 for the Image option. This sets the first image in your ImageList to this button. For the Key option, enter Button1 for the first button, Button2 for the second and so on. This identifies each button uniquely so that we can call events for each later on. Click on Apply and you'll see your button. Continue adding as many buttons as you want and finally click on OK. Your form should look something like this:
The final thing that we have to do is specify an event for each button. To do this, we'll take advantage of the key property of each button. Double click on your ToolBar and enter the following general code in your ToolBar's procedure:
Select Case Button.Key Now enter the key for each of your buttons and specify what your button should do on ButtonClick. If you don't know what this code means, take a look at Conditions and Case Structures in Lesson #3. Your final procedure should look like this:
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) |