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 strips Tabs property, using the Add method. For example, heres 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
Thats all there is to it. In the next topic, well take a look at adding text to the tabs.
Setting Tab Captions
Youve added the tabs you want to your tab strip controlnow how do you add text to those tabs?
At design time, you use the tab strips 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. Thats all it takes.
You can also set a tabs 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 strips 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 strips 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 images 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 youll use (for example, ImageList1) in the box labeled ImageList.
You can also connect images to tabs at runtime. Lets 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 strips 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 strips tabs.
Using A Tab Strip To Display Other Controls
You usually use tab strips to display other controls. Lets see how this works with an example. Here, well use a tab strip to display three picture boxes.
After youve sized the tab strip control as you want it, you can move and size the picture boxes to cover the tab strips client area (in other words, its display area). We do that for all three picture boxes like this, where weve placed them in a control array named PictureControl (we use a With statement because thats what you usually use here if you want to add other code to initialize the controls youre 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, wed 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 weve installed our picture boxes and displayed one on top. But how do we display the others when the user clicks a tab? Well 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 were 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 538533 trening de02 (538)cb uninden pro 538538 542533 53603 (538)538 W08 SKiTI HTML528 533533 540więcej podobnych podstron