Toolbars

Modern Windows applications come complete with extensive toolbars that serve as quick access to various menu choices. In the early days of Windows, these toolbars were nothing but buttons, but today they may include drop downs, combo boxes, and other advanced controls.

Visual Studio .NET makes creating toolbars for your application very easy. The steps are as follows:

  1. Create an image list.

  2. Create a toolbar and associate the image list with the toolbar.

  3. Set up event handlers for the buttons on the toolbar.

  4. Optionally, add additional controls programmatically.

To keep the example simple, start with the OwnerDraw menu you completed earlier and add a simple toolbar.

Creating the ImageList

Begin by dragging an ImageList onto the form. Notice that one of the properties, Images, is marked as a collection. Click on the ellipsis (...) to open the image list. This opens the Image Collection Editor. Click the Add button.

This step opens a dialog for identifying the image you want to add from images you may have stored on disk. Navigate to Program Files\Microsoft Visual Studio .NET 2003\Common7\Graphics\Bitmaps. In this directory, there are two directories with useful icons: OffCtlBr and Assorted. For this example, navigate into OffCtlBr, into Large, and then Color.

Choose the New.bmp file, which adds the bitmap to your collection. Notice that the righthand side of the dialog, with the bitmap properties, is read-only. Add a few more bitmaps, as shown in Figure 18-16.

Figure 18-17. Image collection ...

Get Programming .NET Windows Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.