|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Drawing EllipsesYou use the Circle method to draw ellipses in picture boxes and forms, setting the aspect argument to set the ellipses aspect ratio: object.Circle [Step] ( x, y), radius, [color, [start, end, [aspect]]] Here are the arguments you pass to Circle:
Heres how it works: the aspect ratio is the ratio of the vertical to horizontal axes in the ellipse, and the length of the ellipses major (that is, longer) axis is the value you specify in the radius argument. As an example, we draw an ellipse in both a form and a picture box, Picture1, with this code when the user clicks a command button, Command1. In this case, we use a vertical to horizontal ratio of 0.8 for both ellipses:
Private Sub Command1_Click()
Circle (ScaleWidth / 2, ScaleHeight / 2), _
Switch(ScaleWidth >= ScaleHeight, ScaleHeight / 2, _
ScaleWidth < ScaleHeight, ScaleWidth / 2), , , , 0.8
Picture1.Circle (Picture1.ScaleWidth / 2, Picture1.ScaleHeight / 2), _
Switch(Picture1.ScaleWidth >= Picture1.ScaleHeight, _
Picture1.ScaleHeight / 2, Picture1.ScaleWidth < _
Picture1.ScaleHeight, Picture1.ScaleWidth / 2), , , , 0.8
End Sub
Running the preceding code gives you the result you see in Figure 18.7. The program is a success. Now were drawing ellipses in Visual Basic.
Drawing ArcsYou use the Circle method to draw arcs, using the start, end, and aspect arguments: object.Circle [Step] ( x, y), radius, [color, [start, end, [aspect]]] Here are the arguments you pass to Circle:
In Visual Basic, an arc is part of an ellipse. To draw an arc, you proceed as though you were going to draw an ellipse, including specifying the origin, major radius (in the radius argument), color, and aspect ratio. Then you specify values for the beginning and end of the arc, in radians (in other words, radians go from 0 to 2 * pi for a full circle). Lets see an example. In this case, we draw a convex arc in a form and a concave arc in a picture box, Picture1, when the user clicks a command button, Command1:
Private Sub Command1_Click()
Circle (ScaleWidth / 2, ScaleHeight / 2), _
Switch(ScaleWidth >= ScaleHeight, ScaleHeight / 2, _
ScaleWidth < ScaleHeight, ScaleWidth / 2), , 0, 3.14, 0.8
Picture1.Circle (Picture1.ScaleWidth / 2, Picture1.ScaleHeight / 2), _
Switch(Picture1.ScaleWidth >= Picture1.ScaleHeight, _
Picture1.ScaleHeight / 2, Picture1.ScaleWidth < _
Picture1.ScaleHeight, Picture1.ScaleWidth / 2), , 3.14, 6.28, 0.8
End Sub
The result of this code appears in Figure 18.8. Now were drawing arcs in Visual Basic.
The code for this example is located in the drawarcs 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. |