![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
The ImageList controls Overlay method permits you to overlay one image on another. Because all images are the same size, overlaying them does not make much sense unless part of the top image is transparent, so that the bottom image can show through. This is achieved with the ImageList controls MaskColor property. The color you specify in this property will become transparent in the top image, permitting the second image to show through. Suppose you have an image consisting of a yellow lightning bolt on a green background, and you want to overlay the lightning bolt over another image. First, set the MaskColor property as follows: ImageList1.MaskColor = vbGreen Note that vbGreen is one of Visual Basics intrinsic constants. You can find more details on intrinsic constants by searching the Help system. Once the mask color is set, call the Overlay method to perform the action. The following code overlays the image with Index 2 over the picture with Index 1 and displays the result in a Picture Box: Pbox1.Picture = ImageList1.Overlay 1, 2 You could also create the overlay image and add it as a new image in the same ImageList control: ImageList1.ListImages.Add , overlaid image, _ ImageList1.Overlay 1, 2 You could also specify the images to be overlaid by their Key properties, instead of using the Index property. TreeView ControlThe TreeView control lets you display and manipulate items in a hierarchical view. An example that most of us see every day is Windows Explorer, which uses a TreeView control to display folders and file names. You can select single or multiple items, open and close branches on the tree, and control the way items are displayed. Each item in a TreeView can have an icon associated with it, such as the file folder and page icons used in Windows Explorer. Youre not limited to disk-related items, thougha TreeView control can be used for any information that is arranged hierarchically. To be honest, the TreeView control is not all that easy to understand and use. It is a complicated control, and it doesnt provide the almost-instant gratification that we Visual Basic programmers have perhaps become too accustomed to. Youll have to exercise your noggin a bit before you can get a TreeView control doing just what you want it to. The main reason for the TreeView controls complexity is its structure. It is not, as are most Visual Basic controls, just a single object with a set of properties and methods. Oh no, that would make life too easy. Let me explain:
You can probably see where the confusion comes from. When you want to do something with a TreeView object, its not always clear whether you use the methods and properties of the TreeView object itself, or whether you must manipulate its associated Nodes collection or, perhaps, work directly with a Node object. While the TreeView control by itself can be useful, it really comes into its own when you associate each node in the tree with something else. When TreeView is used for a folder/file display, the association is automatic. What about other associations? Ill be showing you how to associate a Text Box with each node in a tree, and you can use the same or similar techniques to associate other objects with TreeView nodes. I cant show all the details of using the TreeView control, but I can get you started so you can explore further on your own. Ill include a sample application that illustrates the techniques I cover. Adding Nodes To A Tree A TreeView object starts its life with no nodes. In form design, youll see a few sample nodes displayed on the control, but these are present only so you can view the effect of changing properties that determine how the nodes are displayed. They are not present when you run the program. Nodes exist at various levels. The topmost level is the root. Two nodes at the same level are siblings. A node that is subsidiary to another is the child, while the other is the parent. While a program is executing, the user can open a node, displaying all of its children (if any), or close it, hiding any child nodes. You can also open and close nodes in code, so with a single command, you can perform such useful tasks as opening or closing all branches on a given tree. Nodes must be added programmatically using the Add method of the Nodes collection. Heres the syntax: NewNode = TV.Nodes.Add(relative, relationship, key, text, image, selectedImage) TV is the name of the TreeView control. All of the method arguments except one are optional, although its pretty rare to use this method without using at least some of the optional arguments. Lets take a look at them:
Each node added to a tree is automatically assigned a unique Index property. These are nothing more than sequential integers that uniquely identify each node. Each node in a tree, therefore, can always be uniquely identified by its Index property, as well as by its Key property, if you assigned one. As we will see, the Index property provides a method of linking each node to some other object. Note also that each Node object has the Tag property, which can provide another way of both identifying and linking nodes.
|
![]() |
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. Read EarthWeb's privacy statement. |