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
At design time, click that property in the Properties window and click the button with an ellipsis (...) in it to open the Load Picture dialog box. Specify the file you want to load into the picture box, and click on OK.
At runtime, you can use LoadPicture() to load in a picture like this, where we load in an image when the user clicks a command button:
Private Sub Command1_Click()
Picture1.Picture = LoadPicture("c:\vbbb\picturesandimages\image.bmp")
End Sub
TIP: Besides LoadPicture(), Visual Basic also supports LoadResPicture(), which lets you load pictures from resource files. Using LoadResPicture() is useful for localizing a Visual Basic applicationthe resources are isolated in one resource file, and there is no need to access the source code or recompile the application.
If you want to get the picture in a picture box, you also use the Picture property. For example, here we copy the picture from Picture1 to Picture2 when the user clicks a command button:
Private Sub Command1_Click()
Picture2.Picture = Picture1.Picture
End Sub
The Picture property is very useful in Visual Basic because it provides such an easy way of handling images, as you can see in the preceding two code snippets. With the Picture property, you can store images and transfer them between controls.
Besides the Picture property, picture boxes also have an Image property. The Image property is actually the handle to the images bitmap in the picture box and as such is very useful when working with Windows calls directly. You can also assign images from an Image property to a Picture property like this:
Private Sub Command1_Click()
Picture2.Picture = Picture1.Image
End Sub
Adjusting Picture Box Size To Contents
Youve displayed the image of the companys Illustrious Founder in a picture box in your new programbut the picture box was a little small, and you can only see most of the I.F.s forehead. Theres some email waiting for you from the presidents office, and you think you know what it says. How can you make sure picture boxes readjust themselves to fit the picture theyre displaying?
When you load a picture into a picture control, it does not readjust itself to fit the picture (although image controls do)at least, not by default. Picture boxes will resize themselves to fit their contents if you set their AutoSize properties to True. If AutoSize is set to True, you dont have to worry about resizing the picture box, even if you load images into the picture box at runtime. This saves a lot of fiddling with the picture boxs Left, Top, Width, and Height properties.
Aligning A Picture Box In A Form
Picture boxes are special controls in that they can contain other controls (in Visual Basic terms, picture boxes are container controls). In fact, if you place option buttons inside a picture box (just draw them inside the picture box), those option buttons act together as a group.
Besides grouping option buttons together, the original idea here was to provide Visual Basic programmers a (rather rudimentary) way of creating toolbars and status bars in their programs. Thats been superceded now by the toolbar and status bar controls, of course.
To let you create toolbars or status bars, picture boxes have an Align property. You use this property to place the picture box at top, bottom, or on a side of a form. Here are the possible values for Align:
0Align none
2Align bottom
3Align left
4Align right
For example, weve aligned the picture box in Figure 10.5 to the top of the form, giving it a few buttons, and weve set its BackColor property to deep blue to make a rudimentary toolbar.
Figure 10.5 Creating a toolbar with an aligned picture box.
Handling Picture Box Events (And Creating Image Maps)
The New Products Department is on the phone; they want you to design a program to welcome new employees to the company. The program should display a picture of the main plant, and when the new employee clicks part of that image, it should sort of zoom in on it. Can you do something like that in Visual Basic?
Responding to targeted mouse clicks in an image means creating an image map, and you can create one with a picture box. Picture boxes have Click events (and even DblClick events), of course, but Click event handlers only tell you that the picture box was clicked, not where it was clicked:
Private Sub Picture1_Click()
End Sub
The Click event is useful if you want to use picture boxes as sort of image-bearing buttons (although buttons can also display images now). However, if you want to know where in a picture box the user clicked the mouse, use MouseDown. (Besides the full range of mouse events, picture boxes also support key events like KeyDown, KeyPress, and so on.)
Creating An Image Map
Heres an example where we create an image map. Well need to know the exact locations of the various hotspots in the image that do something when clicked, and its easy to find their dimensions and location by using a simple graphics program like the Windows Paint program.
Note, however, that programs like Windows Paint will measure your image in pixels, and if you want to use pixel measurements, not twips, you must set the picture boxs ScaleMode property to vbPixels, like this:
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
End Sub
Well use the image you see in the picture box in Figure 10.6 as our image map and report to users when they click either word, Picture or Box.
Figure 10.6 Creating an image map with a picture box.
In the MouseDown event handler, were passed the location of the mouse click as (X, Y), and we check to see if the mouse went down on either word in the image:
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
If X>16 And X<83 And Y>11 And Y<36 Then
...
End If
If X>83 And X<125 And Y>11 And Y<36 Then
...
End If
End Sub
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:
SHSpec 316 6310C22 The Integration of AuditingBAZA PYTAŃ 319 pytan 5BAZA PYTAŃ 319 pytan 175 Kopia (5)BAZA PYTAŃ 319 pytan 141BAZA PYTAŃ 319 pytan 174 Kopia (3)316 (2)316 317więcej podobnych podstron