![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
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!
When you start the program, it asks you for the name of the trees first node. Then you can click on the Add a Node button to add a new node as either a child or a sibling to the current (highlighted) node, which you select by clicking. New nodes can also be designated as Documents, in which case a Text Box is created and associated with it, or as a Folder, which gets no Text Box. You can enter text in the Text Boxes, and when you click on a different Document node, its text is displayed. Figure 7.3 shows the program executing. This is most definitely a demonstration program, because it lacks many of the features that a real-world program would require, such as the ability to save data to disk or to delete existing nodes. The techniques that it uses could, however, form the nucleus of a useful program that permits the user to organize sections of text in a hierarchical manner. Without much thought, I can already imagine many useful enhancements, such as the ability to combine the text from a selected range of nodes into a single document, or to drag and drop nodes to change the trees organization. There are plenty of possibilities here for you to explore. TabStrip ControlThe TabStrip control is, in my opinion, one of the most useful of the Windows Common Controls. I am sure you have seen it in action many timesfor example, in the Visual Basic Options dialog box. It lets you create multipage dialog boxes with each page represented by a tab at the top of the box. You just click on the associated tab to bring its page into view. With a TabStrip control, you can put a lot of functionality in a single dialog box without making it too large or confusing.
The TabStrip control contains a collection of one or more Tab objects, with the collection itself called Tabs. Each Tab object represents one page in the control. Most of the properties associated with a TabStrip control affect the entire controlfor example, you can specify the font used for the captions on the tabs and whether the tabs are displayed at the top or the bottom of the dialog box. A few properties apply to individual Tab objectsfor example, specifying the caption displayed on the tab or the Tool Tip Text displayed when the user hovers the mouse pointer over the tab. To work with TabStrip properties, you will need to use its property pages, as some properties are not displayed in the normal Visual Basic Properties window. To access a controls property pages, right-click on the control and select Properties from the pop-up menu. You can add tabs to or remove them from the control at design time or runtime. At design time, display the controls property pages and display the Tabs tab. Use the Insert Tab and Delete Tab buttons to add and remove Tabs. Each tab in a TabStrip control is identified by an index number, starting at 1. A tab can also be identified by its Key property. You can assign any unique string to the Key property and then use that value to access the tab at runtime, without worrying about the tabs Index property, which might have changed if additional tabs were added to the TabStrip control. I find it most useful to make a tabs Key property the same as its Caption property. You can access a specific tab by means of either its Index or Key property. Here are two ways to set the Caption property of the Tab object with Index 2 and Key graphics. Assume the TabStrip control is named TabStrip1: TabStrip1.Tabs.Item(2).Caption = Options TabStrip1.Tabs.Item(graphics).Caption = Options Note that because the Item property is the default property of Collection objects, the following two lines of code are exactly equivalent to the previous two lines: TabStrip1.Tabs(2).Caption = Options TabStrip1.Tabs(graphics).Caption = Options To add a tab at runtime, use the Tabs collections Add method. The syntax is as follows: TabStrip1.Tabs.Add IndexNumber, Key, Caption If you omit the IndexNumber argument, the new tab will be placed at the end of the collection. If you specify an IndexNumber argument that is already in use, existing tabs will be bumped up to make room for the new tab. You cannot specify an IndexNumber that is more than one higher than the highest index already in use. To determine this value, which also gives the number of tabs in the TabStrip, query the Tabs collections Count property. For example, assume your project has a TabStrip control named tabOptions; the following code will add two new tabs: tabOptions.Tabs.Add , printing, Printing tabOptions.Tabs.Add , display, Display Each tab can display a small image instead of, or along with, its caption. To display images, you must first load the images into an ImageList control and then associate that control with the TabStrip control (further details on the ImageList control will be presented later in this chapter). The ImageList control must be on the same form as the TabStrip. You create the association between the two controls either by using the TabStrips property pages (on the general page) or in code: TabStrip1.ImageList = ImageList1 You then assign a specific image from the ImageList to a specific tab using the Tabs page in the TabStrip controls property pages or in code. The following code assigns the image whose Index property in the ImageList control is 2 to the tab with Index 1 in the TabStrip control: TabStrip1.Tabs(1).Image = 2 Visual Basic has other properties that control various aspects of the TabStrips appearance, but you can explore these on your own. With some experimentation and the assistance of the Visual Basic Help system, I am sure youll figure them out. More important is that you understand how other controls are displayed on the pages of a TabStrip control and how you manipulate the control to meet the requirements of your program. You might think that each tab in a TabStrip control provides a separate container in which you can place the other controlsText Boxes, Labels, etc.; then, when the user clicks on a tab, the associated controls are automatically displayed. This approach makes sense, but its not the way Microsoft did things. You must provide your own container for the controls to be displayed on each tab, then hide and display the appropriate containers when the user clicks on one of the tabs on the TabStrip control. You can use either Frame or Picture Box controls as containers, but the lower overhead of the Frame control makes it the preferred choice. Heres what you need to do. At design time:
|
![]() |
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. |