|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
The most common use of tab strips today is to organize dialog boxesoften those dialog boxes that let the user set program optionsinto 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 programmers 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 objects 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.
Thats it for the overview. Its time to turn to the Immediate Solutions. Immediate SolutionsAdding An Image List To A FormTo 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:
Now that youve added an image list to a form, how do you add images to that image list? See the next topic. Adding Images To Image ListsTo add images to an image list, you can use the image lists 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.
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 youre done adding images, close the property pages by clicking on OK. You can also add images to an image list using the ListImages collections Add method at runtime like this, where we give the image the key tools:
ImageList1.ListImages.Add ,"tools", LoadPicture("c:\tools.bmp")
Using The Images In Image ListsThe Testing Department is calling again. The 40 picture boxes you have hidden in your program are taking up too much memory. Cant 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, youre 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. Heres 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. Thats all we needthe result appears in Figure 16.7. Now were using the images in an image control. The code for this example is located in the coloranimation folder on this books accompanying CD-ROM.
Setting Image Keys In An Image ListWhen 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 images key in the image lists property pages. For example, set an images Key property to Image1 by entering that text in the Key field. Adding A Tree View To A FormThe 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:
|
|
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. |