533 538




Visual Basic 6 Black Book:Image Lists, Tree Views, List Views, And Tab Strips
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive 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 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




You can also add new tabs at runtime if you add them to the tab strip’s Tabs property, using the Add method. For example, here’s how we add two new tabs to a tab strip control and set their keys:


Private Sub Form_Load()
Dim Tab2, Tab3 As ComctlLib.Tab

Set Tab2 = TabStrip1.Tabs.Add()
Tab2.Key = "Key2"

Set Tab3 = TabStrip1.Tabs.Add()
Tab3.Key = "key3"

End Sub


That’s all there is to it. In the next topic, we’ll take a look at adding text to the tabs.

Setting Tab Captions
You’ve added the tabs you want to your tab strip control—now how do you add text to those tabs?

At design time, you use the tab strip’s property pages. Just right-click the tab strip, select Properties from the menu that appears, and click the Tabs tab, as shown in Figure 16.25. To enter the text for each tab, just select the tab you want to work on, and enter the text for that tab in the box labeled Caption, shown in Figure 16.25. That’s all it takes.
You can also set a tab’s Caption property at runtime. For example, here we set the captions of three tabs to “Tab 1”, “Tab 2”, and so on:


Private Sub Form_Load()
Dim Tab2, Tab3 As ComctlLib.Tab

Set Tab1 = TabStrip1.Tabs(1)
Tab1.Key = "Key1"
Tab1.Caption = "Tab 1"

Set Tab2 = TabStrip1.Tabs.Add()
Tab2.Key = "Key2"
Tab2.Caption = "Tab 2"

Set Tab3 = TabStrip1.Tabs.Add()
Tab3.Key = "key3"
Tab3.Caption = "Tab 3"


Adding this code to a program gives you the captions you see in Figure 16.26.


Figure 16.26  Making use of tab captions.
Setting Tab Images
The Aesthetic Design Department has sent you some email. How about adding some images to that tab strip control in your program? Hmm, you think, how does that work?

You can connect an image list control to a tab strip using the tab strip’s ImageList property, and you can connect the images in that image list to the tabs in the tab strip. At design time, you use the tab strip’s property pages. Just right-click the tab strip, select Properties from the menu that appears, and click the Tabs tab, as shown in Figure 16.25. Then select the tab you want to add an image to, and place the image’s index or key in the image list into the box labeled Image, as shown in Figure 16.25. In addition, you must connect the image list to the tab strip control; select the General tab, shown in Figure 16.25, and enter the name of the image list control that holds the images you’ll use (for example, ImageList1) in the box labeled ImageList.
You can also connect images to tabs at runtime. Let’s see an example in code. Here, we add images displaying large numerals, 1, 2, and 3, as stored in an image list (ImageList1 , which is connected to the tab strip with its ImageList property) to a tab strip’s tabs this way:


Private Sub Form_Load()
Dim Tab2, Tab3 As ComctlLib.Tab

Set Tab1 = TabStrip1.Tabs(1)
Tab1.Key = "Key1"
Tab1.Caption = "Tab 1"
Tab1.Image = 1

Set Tab2 = TabStrip1.Tabs.Add()
Tab2.Key = "Key2"
Tab2.Caption = "Tab 2"
Tab2.Image = 2

Set Tab3 = TabStrip1.Tabs.Add()
Tab3.Key = "key3"
Tab3.Caption = "Tab 3"
Tab3.Image = 3


Now those numerals appear as images in the tabs in the tab strip, as shown in Figure 16.27.


Figure 16.27  Displaying images in a tab strip’s tabs.
Using A Tab Strip To Display Other Controls
You usually use tab strips to display other controls. Let’s see how this works with an example. Here, we’ll use a tab strip to display three picture boxes.

After you’ve sized the tab strip control as you want it, you can move and size the picture boxes to cover the tab strip’s client area (in other words, its display area). We do that for all three picture boxes like this, where we’ve placed them in a control array named PictureControl (we use a With statement because that’s what you usually use here if you want to add other code to initialize the controls you’re displaying):


For intLoopIndex = 0 To PictureControl.Count – 1
With PictureControl(intLoopIndex)
.Move TabStrip1.ClientLeft, TabStrip1.ClientTop,_
TabStrip1.ClientWidth, TabStrip1.ClientHeight
End With
Next intLoopIndex


This puts all the picture boxes on top of each other. How do you make sure only one is showing at a time? You set its ZOrder property to 0; for example, if we want to display the first picture box only, we’d use this code:


For intLoopIndex = 0 To PictureControl.Count – 1
With PictureControl(intLoopIndex)
.Move TabStrip1.ClientLeft, TabStrip1.ClientTop,_
TabStrip1.ClientWidth, TabStrip1.ClientHeight
End With
Next intLoopIndex

PictureControl(0).ZOrder 0


Now we’ve installed our picture boxes and displayed one on top. But how do we display the others when the user clicks a tab? We’ll look into that in the next topic.

Handling Tab Clicks
When the user clicks a tab in a tab strip, the control creates a Click event:


Private Sub TabStrip1_Click()

End Sub


We can display the control that matches the clicked tab by setting its ZOrder to 0. For example, if we use the three picture boxes we added to a tab strip in the previous topic in this chapter, we can bring the selected picture box to the front this way:


Private Sub TabStrip1_Click()
PictureControl(TabStrip1.SelectedItem.Index – 1).ZOrder 0
End Sub


We can also indicate which tab the user clicked in a text box:



Private Sub TabStrip1_Click()
PictureControl(TabStrip1.SelectedItem.Index – 1).ZOrder 0
Text1.Text = "You clicked tab " & Str$(TabStrip1.SelectedItem.Index)
End Sub


Adding this code to a program gives the results you see in Figure 16.28. Now we’re letting the user click the tabs in a tab strip.


Figure 16.28  Clicking tabs in a tab strip.



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.



Wyszukiwarka

Podobne podstrony:
535 538
533 trening de
02 (538)
cb uninden pro 538
538 542
533 536
03 (538)
538 W08 SKiTI HTML
528 533
533 540

więcej podobnych podstron