back
How to Add Buttons to the Visual Basic Toolbar
Note: This project is adapted from an article entitled, "http://Creating a Toolbar in Visual Basic" by John Smiley from the website vbexplorer.com. (This site has lots of interesting articles about Visual Basic programmming).

A cool feature that you can add to your project is to have actual buttons in the toolbar itself. This will give your work a new professional look. There are quite a few steps, but it is easy to do. Follow these instructions like a recipe and you will come out all right. First thing we'll do is add some new features to your toolbox.

  1. Start a new project and make sure you can see the toolbox.
  2. Right click on the tool box and select components.
  3. Scroll till you see the checkbox for "Microsoft Windows Common Controls 6.0. Click on it.
  4. Click on Apply then click on Close. Notice how your toolbox has changed.
  5. Find the new icon on your toolbox called "Toolbar." Click on it then drag one onto your form.
  6. Find the new icon named "ImageList." Put one on your form.
  7. Make sure the ImageList is selected on your form. Right click it and select properties.
  8. Set to 32 by 32.
  9. Click on Apply.
  10. Click the images tab.
  11. Click insert picture. Pick three pictures from your folder.
  12. click Ok.
  13. Right click on the toolbar on your form.
  14. Select properties.
  15. You are now going to change three categories. Change ImageList, Disabled ImageList, and HotImageList all from none to ImageList1.
  16. Click on Apply.
  17. Click on the Buttons Tab.
  18. Click on Insert Button for as many new buttons as you want to add.
  19. Match the index number with the image number. 1 for 1, 2 for 2, and so on.
  20. Click Ok.
  21. At this point we have buttons on the toolbar, but they don't actually do anything yet. When you try to code the buttons, you will discover that when you double-click on the button (to open the code window), what you really are opening up is the toolbar itself. The buttons themselves have merged into the toolbar and the only way to program them separately is do write the following code after double-clicking on the toolbar:

    if Button.index=1 then
    do some action
    end if

    Recall that each button has an index number. You can repeat the if statement for each button in your toolbar.