Visual Basic 6 Black Book:Picture Boxes And Image Controls
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
Well see how to use an image list with picture boxes here. To add an image list control to a program, just follow these steps:
1. Select the Project|Components menu item.
2. Select the Controls tab in the Components box.
3. Select the Microsoft Windows Common Controls item in the Components box and click on OK to close that box.
4. Add a new image list control to your program using the Image List tool in the toolbox.
5. Right-click the new image list control, and select the Properties item in the menu that opens.
6. Click the Images tab in the Property Pages box that opens, and load the images you want to use in the image list using the Insert Picture button.
7. Close the Property Pages box by clicking on OK.
Now youre free to load images from the image list into a picture box. To reach the actual images, you can use the image lists ListImages array of ImageList objects; theres one such object for each image in the image list, and you can reach it with the image lists Picture property.
For example, heres how we load Image 1 (image lists are 1-based, not 0-based) into Picture1 when the user clicks Command1, Image 2 when the user clicks Command2, and Image 3 when the user clicks Command3:
Private Sub Command1_Click()
Picture1.Picture = ImageList1.ListImages(1).Picture
End Sub
Private Sub Command2_Click()
Picture1.Picture = ImageList1.ListImages(2).Picture
End Sub
Private Sub Command3_Click()
Picture1.Picture = ImageList1.ListImages(3).Picture
End Sub
Loading all your images into memory and storing them with an image list can be a valuable asset when working with multiple images and picture boxes this way.
Adding Text To A Picture Box
Besides drawing figures, picture boxes support drawing text as well. This can come in very handy to label the parts of a figure in a picture box.
You draw text in a picture box with its Print method, passing that method the text you want to print. Where does that text appear? It appears at the location set by the picture boxs CurrentX and CurrentY propertiesthat is, at (CurrentX, CurrentY) in the picture box (with respect to the upper left corner of the picture box).
Keep in mind that picture boxes use twips (1/1440s of an inch) as their default measurement unit. You can change that to, say, pixels by setting the picture boxs ScaleMode property to vbPixels:
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
...
Then we can specify an absolute location at which to display text:
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
Picture1.CurrentX = 25
Picture1.CurrentY = 20
...
Finally, we print the text in the picture box with the Print method; here, we just print the text Text in a picture box!:
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
Picture1.CurrentX = 25
Picture1.CurrentY = 20
Picture1.Print ("Text in a picture box!")
End Sub
Make sure the picture boxs AutoRedraw property is set to True, which it needs to be for the picture box to display text. The results of the preceding code appear in Figure 10.10. Now were displaying text in picture boxes.
Figure 10.10 Printing text in a picture box.
Formatting Text In A Picture Box
The Aesthetic Design Department is calling. The text your program uses to label images in picture boxes is fine, but how about making it, say, bold and italic to emphasize whats going on? You think, can you do that?
Yes, you can. You can format text in a picture box using the FontBold, FontItalic, FontStrikethru, and FontUnderline properties. Each of those properties does just what it says: when you set a property to True, that property applies the next time you use the Print method in the picture box.
You can also format the placement of text using the CurrentX and CurrentY properties; setting these properties sets the location where text will next appear when you use the Print method. In addition, you can determine the height and width of a string of text with the TextHeight and TextWidth methods.
Heres an example. First, set the picture boxs AutoRedraw property to True, which you need to display text. Next, we set the measurement units in a picture box to pixels, set the CurrentX and CurrentY properties, and print a plain string of text:
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
Picture1.CurrentX = 25
Picture1.CurrentY = 20
Picture1.Print ("Text in a picture box!")
...
Next, we skip to the next line using TextHeight(), set FontUnderline to True, and print some underlined text:
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
Picture1.CurrentX = 25
Picture1.CurrentY = 20
Picture1.Print ("Text in a picture box!")
Picture1.CurrentX = 25
Picture1.CurrentY = Picture1.CurrentY + Picture1.TextHeight("ABCDEFG")
Picture1.FontUnderline = True
Picture1.Print ("Underlined text.")
...
Finally, we set FontBold to True as well, skip to the next line, and print bold underlined text:
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
Picture1.CurrentX = 25
Picture1.CurrentY = 20
Picture1.Print ("Text in a picture box!")
Picture1.CurrentX = 25
Picture1.CurrentY = Picture1.CurrentY + Picture1.TextHeight("ABCDEFG")
Picture1.FontUnderline = True
Picture1.Print ("Underlined text.")
Picture1.CurrentX = 25
Picture1.CurrentY = Picture1.CurrentY + Picture1.TextHeight("ABCDEFG")
Picture1.FontBold = True
Picture1.Print ("Bold underlined text.")
End Sub
Running this code yields the result shown in Figure 10.11, where the picture box displays formatted text. Its no rich text box, but you can use the text capabilities of a picture box to display labels and call-outs for graphics.
Figure 10.11 Formatting text in a picture box.
Clearing A Picture Box
How can you clear the current image in a picture box and start over? You use the Cls method. Heres an example that clears a picture box when the user clicks a command button:
Private Sub Command1_Click()
Picture1.Cls
End Sub
TIP: The name Cls comes from the original DOS days, when it stood for clear screen. That command was adopted in Microsoft Basic, and from there became a part of Visual Basic, even though its no longer intended to clear the screen.
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:
326 331LM231 331326 327323 32607 (331)331 (B2006) Badanie rocznego sprawozdania finasowego326 (2)331 (2)09 (326)MTA 291 2 V, MTA 331 2 V325 32621 (326)więcej podobnych podstron