DOCKING TOOLBARS ON FORMS USING THE TOOLBAR CONTROL

For the most part, Access's built-in toolbars do a good enough job when it comes to using them in applications. The ActiveX ToolBar control has one advantage over Access 97's toolbars in that you can place a toolbar on an individual form. The way this is demonstrated here is to emulate the main WindowsCommonControls form by using a ToolBar control instead of a TabStrip control. The form that's used, WindowsCommonControlsToolbar, is in the Chap14.mdb database (on the CD in the ExamplesChap14 folder).

The ToolBar control can take images supplied by the ImageList control just like the TabStrip and a few of the other Windows 95 interface controls do. Figure 14.20 shows the WindowsCommonControlsToolbar form, which uses the ToolBar control complete with Tooltips. The images are supplied with a copy of the ImageList control; this control is covered earlier in the section “Using the ImageList Control with the TabStrip Control.”

Figure 14.20. You can place ToolBar controls on individual forms.


Creating a ToolBar control follows along the lines of the other controls in that you insert buttons, which are kept in a collection called Buttons, and each has a set of properties. Figure 14.21 shows the properties for a button on the ToolBar control's property sheet. (To open the property sheet, simply double-click the ToolBar control itself.)

Figure 14.21. There's a set of properties for each button on the ToolBar control.


You can create different toolbar button styles, based on what you set the Style property to be for the individual buttons. The possible settings for the Style property are

  • 0 - tbrDefault. A standard toolbar button (the default).

  • 1 - tbrCheck. A check button; can be checked and unchecked.

  • 2 - tbrButtonGroup. Stays selected until another button is clicked.

  • 3 - tbrSeparator. Used for separating buttons on the toolbar. It's a fixed width of 8 pixels.

  • 4 - tbrPlaceholder. Same as Separator, except that you can specify a width using the Width property.

  • 5 - tbrDropDown. Allows for the use of a drop-down control.

At runtime, the ToolBar control has a ButtonClick event that you use from other controls. When you create a ButtonClick event procedure, Access automatically sets it up to pass the current button in as an object. Listing 14.14 shows this event procedure.

Listing 14.14. Chap14.mdb: Swapping Source Objects Based on a Button
Private Sub ocxToolbar_ButtonClick(ByVal Button As Object)

   Me.Painting = False
   Me!ocxToolbar.SetFocus

   Select Case Button.KEY
     Case "ListView"
         Me!subControlExample.SourceObject = _
            "WindowsCommonControlsListView"
     Case "Progress"
         Me!subControlExample.SourceObject = _
            "WindowsCommonControlsProgressBar"
     Case "Slider"
         Me!subControlExample.SourceObject = _
            "WindowsCommonControlsSlider"
     Case "Rich"
         Me!subControlExample.SourceObject = _
            "WindowsCommonControlsRichText"
     Case "TreeView"
         Me!subControlExample.SourceObject = _
            "WindowsCommonControlsTreeView"
   End Select

   UpdateStatusBarControl Button.Index

   Me.Painting = True

End Sub

This code performs the following steps:

1.
The current toolbar button is passed in as an Object.

2.
Painting is turned off, and the focus is set to the ToolBar control called ocxToolbar.

3.
It performs a Select Case statement that reads the Key property that has been set, and swaps out the SourceObject property accordingly.

4.
The UpdateStatusBarControl subroutine is called with the Button index property being passed.

5.
Painting is turned on.

The UpdateStatusBarControl subroutine in step 4 updates the ActiveX StatusBar control that's located at the bottom of the form. The code for this is as follows:

Sub UpdateStatusBarControl(intChoice As Integer)

  Set Me!ocxStatusBar.Panels(3).Picture = _
           Me!ocxImageList.ListImages(intChoice).Picture
  Me!ocxStatusBar.Panels(4).Text = _
           Me!ocxToolbar.Buttons(intChoice).ToolTipText

End Sub

The first thing the UpdateStatusBarControl subroutine does is update one of the panels of the StatusBar control with the image of the current ToolBar control button selected. Next, another panel is updated with the ToolTipText property of the current ToolBar control button. For more information on using the StatusBar control, see the earlier section “Creating Status Bars for Individual Forms with the StatusBar Control.”

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.54.108