UNDERSTANDING THE ACTIVEX WINDOWS COMMON CONTROLS

Windows has a number of controls that you can access through ActiveX controls. Nine ActiveX controls are available with Comctl32.ocx, which is automatically registered when you install the Microsoft Office Developer (MOD). Table 14.1 lists the controls available.

Table 14.1. The ActiveX Windows Common Controls Included in the MOD
OCX Name Description
ImageList This control holds bitmaps and icons that the other controls can use.
ListView This control displays images in the same four different views that are available with the Explorer.
Progress Use this control to display the progress of a task anywhere on any form needed.
Rich Textbox This control allows you to use different fonts, colors, sizes, italics, and so forth for each character of the text box, if desired.
Slider This control displays a vertical or horizontal slider control.
StatusBar You can now have a status bar not only on the main Access screen, but on each individual form.
TabStrip In addition to standard tabs, this tab control allows you to arrange tabs in multiple rows and to display images on tabs.
ToolBar By using this control, you have more control over toolbars.
TreeView This control allows you, as the developer, to view data in a hierarchical form.

Note

A number of other ActiveX controls are included in the MOD. The controls listed in Table 14.1 are the ones described in this chapter.


Using the TabStrip Control

The native Access Tab control now performs the tasks that the ActiveX TabStrip control accomplishes. However, because this chapter is on ActiveX controls, the TabStrip control is also discussed.

Understanding the TabStrip Control's Features

With the TabStrip control, you can create a tabbed form with multiple rows. All you have to do is set the MultiRow property to true. Figure 14.1 shows an example of multiple tab rows created with the TabStrip control.

Figure 14.1. The TabStrip control can show multiple tab rows with the MultiRow property.


The TabStrip control also allows you to display images on the tabs. In Figure 14.1, you can see the ImageList control that specifies the list of images to use. The actual images are stored in another Windows Common Control—the ImageList control.

Using the ImageList Control with the TabStrip Control

To specify a list of images, insert an ImageList control onto a form in which you have a TabStrip control. Then open the ImageList control-specific property sheet and select the Images tab. You can then choose Insert Picture and add a list of images. Figure 14.2 shows a list of selected images.

Figure 14.2. These bitmaps make up an image list used with the TabStrip control.


Again, after you create the image list, you can then do the following:

1.
Open the TabStrip control-specific property sheet.

2.
Set the ImageList property on the TabStrip control to the name of the ImageList control.

3.
Select the Tabs tab on the property sheet.

4.
For the Image property for each tab, set the value to the corresponding image index. The ListView image is 1, the Slider image is 2, the Progress image is 3, and so forth.

The images now appear on each tab.

Tip

You can also use the ImageList control with the ListView, ToolBar, and TreeView controls.


For more information on how to use the ImageList control, see the later section “Taking a Closer Look at the ImageList Control.”

Differences in Programming the Access Tab and ActiveX TabStrip Controls

Using the Access Tab control and ActiveX TabStrip control in VBA is basically the same, except that different properties are used and that the routines are attached to different events. When using the Tab control, the default Value property is used; the TabStrip control, on the other hand, uses the SelectedItem.Index property.

Listing 14.1 shows the code used for the Access Tab control and attached to the Change event.

Note

The code in Listing 14.1 is displayed here, but is not in the sample database because the Access Tab control is usually used. The code is presented here to show how to use the TabStrip control with VBA, when you use it with other languages such as Visual Basic.


Listing 14.1. Chap14.mdb: Programming the Access Tab Control
Private Sub Tabs_Change()

    On Error GoTo Error_Tabs_Change

    Me.Painting = False

    ' The Tab value property is zero based
    Select Case Me!Tabs.Object.Value
       Case 0
           Me!CustomerSub1.Visible = True
           Me!CustomerSub2.Visible = False
           Me!CustomerSub3.Visible = False
       Case 1
           Me!CustomerSub1.Visible = False
           Me!CustomerSub2.Visible = True
           Me!CustomerSub3.Visible = False
       Case 2
           Me!CustomerSub1.Visible = False
           Me!CustomerSub2.Visible = False
           Me!CustomerSub3.Visible = True
    End Select
    Me.Painting = True

Exit_Tabs_Change:
    Exit Sub

Error_Tabs_Change:
    MsgBox Err.Description
    Resume Exit_Tabs_Change:
End Sub

Listing 14.2 shows the same code used with the TabStrip control. Notice that you attach it to the Click event. Also notice that instead of Value, you look at SelectedItem.Index.

Listing 14.2. Programming the TabStrip Control
Private Sub ocxTabStrip_Click()

    On Error GoTo Error_ocxTabStrip Click

    Me.Painting = False

    ' The TabStrip Selected.Index property is zero-based
    Select Case Me!ocxTabStrip.SelectedItem.Index
       Case 0
           Me!CustomerSub1.Visible = True
           Me!CustomerSub2.Visible = False
           Me!CustomerSub3.Visible = False
       Case 1
           Me!CustomerSub1.Visible = False
           Me!CustomerSub2.Visible = True
           Me!CustomerSub3.Visible = False
       Case 2
           Me!CustomerSub1.Visible = False
           Me!CustomerSub2.Visible = False
           Me!CustomerSub3.Visible = True
    End Select
    Me.Painting = True

Exit ocxTabStrip Click:
    Exit Sub

Error ocxTabStrip Click:
    MsgBox Error$
    Resume Exit ocxTabStrip Click

End Sub

In the end, with Access, you will want to use the standard Access tab control.

For more information on paging techniques in multiple forms, see Chapter 9, “Creating Powerful Forms.”

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

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