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
And we do the same for the remaining two items:
Private Sub Form_Load()
Dim colHeader As ColumnHeader
Dim intLoopIndex As Integer
For intLoopIndex = 1 To 4 'Label headers
Set colHeader = ListView1.ColumnHeaders.Add()
colHeader.Text = "Field " & intLoopIndex
colHeader.Width = ListView1.Width / 4
Next intLoopIndex
Dim ListItem1 As ListItem
Set ListItem1 = ListView1.ListItems.Add()
ListItem1.Text = "Item 1"
ListItem1.Icon = 1
ListItem1.SmallIcon = 1
ListView1.ListItems(1).ListSubItems.Add , , "Field 2"
ListView1.ListItems(1).ListSubItems.Add , , "Field 3"
ListView1.ListItems(1).ListSubItems.Add , , "Field 4"
Dim ListItem2 As ListItem
Set ListItem2 = ListView1.ListItems.Add()
ListItem2.Text = "Item 2"
ListItem2.Icon = 1
ListItem2.SmallIcon = 1
ListView1.ListItems(2).ListSubItems.Add , , "Field 2"
ListView1.ListItems(2).ListSubItems.Add , , "Field 3"
ListView1.ListItems(2).ListSubItems.Add , , "Field 4"
Dim ListItem3 As ListItem
Set ListItem3 = ListView1.ListItems.Add()
ListItem3.Text = "Item 3"
ListItem3.Icon = 1
ListItem3.SmallIcon = 1
ListView1.ListItems(3).ListSubItems.Add , , "Field 2"
ListView1.ListItems(3).ListSubItems.Add , , "Field 3"
ListView1.ListItems(3).ListSubItems.Add , , "Field 4"
End Sub
Thats itwhen you set ListView1s View property to lvwReport , the preceding code gives us the results you see in Figure 16.21. Now weve added text to all the fields in our list view.
Figure 16.21 Adding column text to list view items.
Handling List View Item Clicks
Your list view is set up, and youve displayed the items you want in it in the view type you want. But now what? How do you let the user use that list view?
When the user clicks an item in a list view, the control generates an ItemClick event:
Private Sub ListView1_ItemClick(ByVal Item As ComctlLib.ListItem)
End Sub
The item that was clicked is passed to us as the argument named Item , and you can access its Index or Key properties to determine which item it is. As an example, here we display the items index in a text box, Text1 , when the user clicks it:
Private Sub ListView1_ItemClick(ByVal Item As ComctlLib.ListItem)
Text1.Text = "You clicked item " & Item.Index
End Sub
Adding this code to a program gives us the results you see in Figure 16.22when the user clicks an item, we report which item was clicked in the text box at bottom in that figure.
Figure 16.22 Handling list view clicks.
Besides item clicks, you can also handle column header clickssee the next topic.
Handling List View Column Header Clicks
How do you know when the user clicks a column header in a list view? The control generates a ColumnClick event, which you can handle in its event handler:
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As _
ComctlLib.ColumnHeader)
End Sub
The column header the user clicked is passed to us as the ColumnHeader argument, and you can determine which column header was clicked with its Index property. For example, here we display which column the user has clicked with a message in a text box, Text1:
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As _
ComctlLib.ColumnHeader)
Text1.Text = "You clicked column " & ColumnHeader.Index
End Sub
Now we can determine which column header the user clicked, as shown in Figure 16.23.
Figure 16.23 Determining which column was clicked in a list view.
Adding A Tab Strip To A Form
The Testing Department is calling again. There are just too many dialog boxes in your program. How can you fix that?
You can group the dialog boxes into one, using a tab strip; as the user selects tabs in the tab strip, you can display the contents that were separate dialog boxes in panels that appear when their tab is clicked. For an example of how this works, select the Project Properties item in the Visual Basic Project menu.
To add a tab strip control to a form, follow these steps:
1. Select the Project|Components menu item.
2. Click the Controls tab in the Components dialog box that opens.
3. Select the Windows Common Controls item.
4. Click on OK to close the Components dialog box.
5. The preceding steps add the Tab Strip Control tool to the toolbox. Draw a tab strip in the form as you want it.
6. Set the tab strips properties, and add the code you want.
After you add a tab strip control to your program, its up to you to tailor it the way you want it, by adding new tabs, text, and images to those tabs, and so on. Well develop a tab strip example in the next topics in this chapter, and you can see that program at work in Figure 16.24. When the user clicks one of the three tabs in the program, we display a new panel of the tab strip control, each of which displays a picture box with a different color.
Figure 16.24 Our tab strip example program at work.
This example has these controls: a tab strip, TabStrip1 ; three picture boxes, Picture1 through Picture3 , which each hold a solid-color picture (and with their AutoSize property set to True); a text box, Text1 , so we can report which tab the user has clicked; and an image list control, ImageList1 , which holds three images that we use in the tabs of the tab strip.
The code for this example is located in the tabstrip folder on this books accompanying CD-ROM.
Inserting Tabs Into A Tab Strip Control
When you first add a tab strip control to a form, that control has one tab in it (and it cant have less than oneif you take that one tab out of the control, youll find it back in place the next time you load the program into Visual Basic). How do you add others?
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.
Figure 16.25 Adding tabs to a tab strip control.
You add new tabs by clicking the Insert Tab button, and at the same time you can set the tabs Text , Key , and other properties.
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:
528 533533 53811 (528)533 trening de528 (2)readme (528)II CSK 528 06 1I PKN 528 99533 536528,15,artykul524 528533 540522 528README (533)więcej podobnych podstron