606 609




Visual Basic 6 Black Book:Working With 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 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




Setting Drawing Scales
Forms and picture boxes have a number of scale properties, and perhaps the most popular one is ScaleMode, which sets the units of measurement in a picture box. Here are the possible values for ScaleMode (note that when you set the scale mode of a picture box, all measurements are in those new units, including coordinates passed to your program, like mouse down locations):

•  vbUser—0; indicates that one or more of the ScaleHeight, ScaleWidth, ScaleLeft, and ScaleTop properties are set to custom values
•  vbTwips—1 (the default); twip (1440 twips per logical inch; 567 twips per logical centimeter)
•  vbPoints—2; point (72 points per logical inch)
•  vbPixels—3; pixel (smallest unit of monitor or printer resolution)
•  vbCharacters—4; character (horizontal equals 120 twips per unit; vertical equals 240 twips per unit)
•  vbInches—5; inch
•  vbMillimeters—6; millimeter
•  vbCentimeters—7; centimeter
•  vbHimetric—8; HiMetric
•  vbContainerPosition—9; units used by the control’s container to determine the control’s position
•  vbContainerSize—10; units used by the control’s container to determine the control’s size

For example, to report the mouse location in pixels in a form using two text boxes, Text1 and Text2, we set the form’s ScaleMode property to vbPixels when the form loads:


Private Sub Form_Load()
ScaleMode = vbPixels
End Sub


This means that the X and Y values for the mouse location passed to us will be in pixels, so we can display those coordinates in the text boxes this way:



Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As _
Single, Y As Single)
Text1.Text = "Mouse x location (in pixels): " & Str(X)
Text2.Text = "Mouse y location (in pixels): " & Str(Y)
End Sub


The result of the preceding code appears in Figure 18.14.


Figure 18.14   Displaying mouse location in pixels.
If you set the scale mode to vbUser, you can define your own units by setting the dimensions of the picture box using the ScaleLeft, ScaleTop, ScaleWidth, and ScaleHeight properties. This can be very useful if you’re plotting points and want to use a picture box as a graph.

TIP:  The ScaleWidth and ScaleHeight properties of a picture box hold the image’s actual dimensions (in units determined by the ScaleMode property), not the Width and Height properties, which hold the control’s width and height (including the border).

The code for this example is located in the pixelmouse folder on this book’s accompanying CD-ROM.

Using The Screen Object
The Visual Basic Screen object offers you a lot of information about the current display. Here are that object’s properties:


•  TwipsPerPixelX—Twips per pixel horizontally
•  TwipsPerPixelY—Twips per pixel vertically
•  Height—Screen height
•  Width—Screen width
•  Fonts—Collection of names of the available fonts
•  FontCount—Total number of screen fonts available
•  ActiveControl—Currently active control
•  ActiveForm—Currently active form
•  MouseIcon—Returns or sets a custom mouse icon
•  MousePointer—Returns or sets a value indicating the type of mouse pointer displayed when the mouse is over a particular part of an object at runtime

Resizing Graphics When The Window Is Resized
The Testing Department is on the phone. When the user resizes your SuperDuperGraphicsPro program, the graphics in the program don’t resize themselves. You ask, should they? They say, yes.
You can use the Resize event to catch window or picture box resizes. Let’s see an example. Here, we add a new subroutine, DrawBox, to a form. This subroutine draws a rectangle in a form:


Private Sub DrawBox()
Line (ScaleWidth / 4, ScaleHeight / 4)–(3 * ScaleWidth / 4, _
3 * ScaleHeight / 4), , B
End Sub


We can call DrawBox in the Load event to draw the box the first time (set the form’s AutoRedraw property to True to draw graphics in the Form Load event):


Private Sub Form_Load()
DrawBox
End Sub


When the user resizes the form, we clear the form and redraw the box in the Form Resize event:


Private Sub Form_Resize()
Cls
DrawBox
End Sub


Now the program resizes its graphics to match the user’s actions. The code for this example is located in the resizer folder on this book’s accompanying CD-ROM.




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:
609 611
README (609)
604 606
Nuestro Circulo 609 VUGAR VASHIMOV
604 606
609 613
W Ziemi Obiecanej (1615 606 p n e )
609 612
606 (2)
PIONEER PDR 609
606 613
609 (2)
ONKYO KODY DO PILOTA 506,576,606,5100codes

więcej podobnych podstron