Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Graphics
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 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
(Publisher: The Coriolis Group)
Author(s): Peter G. Aitken
ISBN: 1576102815
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
TIP: Understanding The Paint Event And The AutoRedraw Property
The Paint event is related to the AutoRedraw property. Both Form and Picture Box objects have an AutoRedraw property. If AutoRedraw is set to Off (the default), graphics and text are written only to the screen, and the Paint event is triggered, as indicated in Figure 12.3. The graphics and text are not persistentthey must be redrawn using the Paint event procedure if the object is uncovered (after being covered by another screen element) or restored (after being minimized). If AutoRedraw is set to On, the graphics and text are saved in memory, as well as being written to the screen, and the display is persistentautomatically refreshed from this memory image if the object is restored or uncovered. In this case, the Paint event does not occur. AutoRedraw applies only to graphics and text created with the Line, Circle, Pset, and Text methods; bitmaps and metafiles are persistent regardless of the AutoRedraw setting.
Setting AutoRedraw to On slows down screen display of graphics and consumes extra memory. Both of these effects are particularly noticeable with large objects.
Figure 12.3 Events associated with loading, showing, sizing, and unloading forms.
Defining Custom Coordinates
If Visual Basics assortment of coordinate units doesnt suit you, define your own. A custom coordinate system can include moving the origin to another location, a useful technique for certain applications. For example, a program that draws maps could set the graphical coordinate units to a meaningful value, such as miles or latitude and longitude. You can also flip the Y axis so positive values move upward, making it easier to use the Cartesian coordinates commonly used in graphs. A custom coordinate system affects not only graphics operations, but also the placement of controls in a container.
To define a custom coordinate systemwhich is possible only for Form, Picture Box, and Printer objectsuse the Scale method. The syntax is
objectname.Scale (left, top)-(right, bottom)
where (left, top) are the new coordinates of the left and top of the object, and (right, bottom) are the new coordinates for the right and bottom of the object. For example
Form1.Scale (0, 0)-(100, 100)
sets a coordinate system where the top-left corner of the object has coordinates (0, 0) and the lower-right corner has coordinates (100, 100). This example does not move the origin, but only changes the measurement unit to be 1/100 of the object dimension. In contrast, the statement
Form1.Scale (0, 100)-(100, 0)
sets the same measurement units, then moves the origin to the lower-left corner of the object and inverts the Y axis so positive values move upward. When you use Scale to set custom coordinates, Visual Basic automatically changes the objects ScaleMode property to 0. As you saw in Table 12.1, this indicates that a custom coordinate system is in effect.
Applying the Scale method changes the objects ScaleWidth, ScaleHeight, ScaleLeft, and ScaleTop properties to reflect the new coordinates. For instance, after executing the previous Scale method, the objects ScaleWidth property would be 100 and its ScaleHeight property would be 100. You can set these properties individually if you want to modify only part of the objects coordinate system. Thus, the statement
object.ScaleWidth = 100
results in the objects horizontal measurement unit being set to 1/100 of its width, while the location of the origin and the vertical measurement unit remain unchanged. Executing the Scale method with no arguments, like this
object.Scale
will reset the coordinate system to the default (twips with the 0, 0 point at the top left).
You must be aware that the Scale method defines its units based on the objects size at the time the method is executed. Subsequent changes to the objects size are not automatically taken into account. Well see how this works in the custom coordinate demonstration program.
This program uses the Circle method in a For...Next loop to draw a series of circles on a form. Youll learn the details of the Circle method later in the chapteryou neednt worry about it now. The program consists of a form without controls. Leave all of the forms properties at their default values and save your work, calling both the form and the project SCALE. Next, place the code shown in Listing 12.3 in the forms Paint event procedure.
Listing 12.3 The Paint event procedure.
Private Sub Form_Paint()
Dim i As Integer
Cls
For i = 1 To 5
Circle (150 * i, 100 * i), 50 * i
Next i
End Sub
The Circle method draws a circle with its center at the specified coordinates (the values in the parentheses) and with the specified radius. When you execute the program, it will look more or less like Figure 12.4. I say more or less, because the appearance may vary slightly if you made your form a different size than I did or if your display hardware is different from mine.
Figure 12.4 The circles drawn with the forms default coordinate system.
After running the program and seeing what the display looks like, add the following statement to the forms Load event procedure:
Scale (0, 1000)-(1000, 0)
Run the program again, and youll see a quite different display, as shown in Figure 12.5.
TIP: Automatic Object References
Why is it that we can sometimes refer to properties and methods without specifying an object? For example, you can write simply Scale (0, 1000)-(1000, 0) rather than Form1.Scale (0, 1000)-(1000, 0). In an event procedure, a reference to a property or method automatically refers to the object that received the event, unless another object is specified.
Looking at the new display, youll see that not only are the circles larger (because the coordinate unit we specified is much larger than a twip), but the circles climb from the bottom of the form rather than descending from the top (because we inverted the Y axis). If you change the size of the form while the program is running, the circles stay the same sizethey do not grow or shrink along with the form.
Now lets try one more thing. Copy the Scale (0, 1000)-(1000, 0) statement and paste it in the Paint event procedure, just after the Cls statement. When you run the program and increase the size of the form by dragging its border, the circles are redrawn to keep the same size relative to the form. By resetting the forms coordinate system each time it is painted, we ensure that the coordinate system units are always defined relative to the forms current sizenot according to its original size.
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. Read EarthWeb's privacy statement.
Wyszukiwarka
Podobne podstrony:
12 04 2010 płockieKobieta nie ma prawa bez zgody męża wyjść z domu (12 04 2009)TI 01 12 04 T B plZajecia 12 04 1012 04Wielkanoc w Bagdadzie (12 04 2009)12 04 Roboty dekarskie i izolacyjnesurowce II st 2011 12 04 ST i NST metody badania surowcówsurowce II st 2011 12 04 ST i NST metody badania surowcówDz U 12 04 2013rWM Cw9 Spraw v13 12 04 15tokarka 24,04,12więcej podobnych podstron