|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Setting Drawing ScalesForms 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):
For example, to report the mouse location in pixels in a form using two text boxes, Text1 and Text2, we set the forms 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.
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 youre plotting points and want to use a picture box as a graph.
The code for this example is located in the pixelmouse folder on this books accompanying CD-ROM. Using The Screen ObjectThe Visual Basic Screen object offers you a lot of information about the current display. Here are that objects properties:
Resizing Graphics When The Window Is ResizedThe Testing Department is on the phone. When the user resizes your SuperDuperGraphicsPro program, the graphics in the program dont resize themselves. You ask, should they? They say, yes. You can use the Resize event to catch window or picture box resizes. Lets 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 forms 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 users actions. The code for this example is located in the resizer folder on this books accompanying CD-ROM.
|
|
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. |