Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


The most common use of tab strips today is to organize dialog boxes—often those dialog boxes that let the user set program options—into many different panels, all hidden from view except the current one the user has selected. In this way, you can pack a great deal into a small space in a dialog box and avoid the need for many dialog boxes.

From the programmer’s point of view, a tab strip control consists of one or more Tab objects in a Tabs collection. At both design time and runtime, you can set the Tab object’s appearance by setting properties, and at runtime, by invoking methods to add and remove Tab objects.

The Tab Strip Control tool appears as the eleventh tool down on the right in the Visual Basic toolbox in Figure 16.5.


Figure 16.5  The Tab Strip Control tool.

That’s it for the overview. It’s time to turn to the Immediate Solutions.

Immediate Solutions

Adding An Image List To A Form

To work with many Windows common controls, you need to use image lists. How do you add an image list control to a program? Just follow these steps:

1.  Select the Project|Components menu item.
2.  Click the Controls tab in the Components dialog box that opens.
3.  Select the Windows Common Controls entry.
4.  Close the Components dialog box by clicking on OK.
5.  Double-click the Image List Control tool (see Figure 16.1 at bottom, on the right) to add an image list control to a form. This control is invisible at runtime, so its size and location don’t make much difference.

Now that you’ve added an image list to a form, how do you add images to that image list? See the next topic.

Adding Images To Image Lists

To add images to an image list, you can use the image list’s property pages at design time. Just right-click the image list and select the Properties item in the menu that opens. Next, click the Images tab in the property pages, as shown in Figure 16.6.


Figure 16.6  Adding images to an image list.

To insert images into the image list control, just use the Insert Picture button; clicking that button lets you search for image files on disk. Each successive image gets a new Index value, starting at 1 and counting up. If you wish, you can also give each image a Key value (a unique text string identifier) by entering text in the box labeled Key when you add an image.

When you’re done adding images, close the property pages by clicking on OK.

You can also add images to an image list using the ListImages collection’s Add method at runtime like this, where we give the image the key “tools”:

ImageList1.ListImages.Add ,"tools", LoadPicture("c:\tools.bmp")


TIP:  You should note that when the image list control is bound to another Windows common control, images of different sizes can be added to the control, but the size of the image displayed in the associated Windows common control will be constrained to the size of the first image added to the image list.

Using The Images In Image Lists

The Testing Department is calling again. The 40 picture boxes you have hidden in your program are taking up too much memory. Can’t you do something else to store images?

You can. An image control can take up much less memory. Usually when you use an image control, you’re storing images for a Windows common control. Those controls have an ImageList property, which you set to the name of the image list control you want to use (for example, ImageList1). From then on, you can associate the elements of the Windows common control with the images in the associated image list either by index or by key value.

However, you can also use image list controls with other controls, such as picture boxes. Here’s an example taken from our earlier chapter on picture boxes that will create some graphics animation. We store images in an image list and swap them into a picture box in this example.

Add a timer control with its Interval property set to 1000 (that is, 1 second), setting its Enabled property to False; a picture box, Picture1 , with its AutoSize property set to True; an image list control, ImageList1 , adding two images to the image list control (we used image1.bmp and image2.bmp, which are just bands of blue and red, in this example); and a command button, Command1 , labeled Start Animation.

When the user clicks the Start Animation button, we enable the timer:

Private Sub Command1_Click()
    Timer1.Enabled = True
End Sub

Then we toggle a Boolean variable, blnImage1 , and alternate images from the image list control every second:

Private Sub Timer1_Timer()
    Static blnImage1 As Boolean

    If blnImage1 Then
        Picture1.Picture = ImageList1.ListImages(1).Picture
    Else
        Picture1.Picture = ImageList1.ListImages(2).Picture
    End If

    blnImage1 = Not blnImage1

End Sub

Note how we refer to the images in the image control, using the ListImages collection this way: ImageList1.ListImages(1).Picture.

That’s all we need—the result appears in Figure 16.7. Now we’re using the images in an image control. The code for this example is located in the coloranimation folder on this book’s accompanying CD-ROM.


Figure 16.7  Using the images in an image control for animation.

Setting Image Keys In An Image List

When you add an image to an image list control, that image gets a new index value automatically. However, you can also refer to images with the Key property. The key is a unique text string that identifies the image just as its index does, and in Windows common controls, you can refer to an image in an image list by either its index or key.

You set an image’s key in the image list’s property pages. For example, set an image’s Key property to Image1 by entering that text in the Key field.

Adding A Tree View To A Form

The Testing Department is calling again. There sure is a lot of data in your new program, SuperDuperDataCrunch . Yes, you agree, there is. How about using a tree view instead? Hmm, you think, how does that work?

To add a tree view control to a form, follow these steps:

1.  Select the Project|Components menu item.
2.  Click the Controls tab in the Components dialog box that opens.
3.  Select the Windows Common Controls item.
4.  Click on OK to close the Components dialog box.
5.  The preceding steps add the Tree View Control tool to the toolbox. Draw a tree view in the form as you want it.
6.  Set the tree view’s properties, and add the code you want.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.