596 599




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




Drawing Ellipses
You use the Circle method to draw ellipses in picture boxes and forms, setting the aspect argument to set the ellipse’s aspect ratio:


object.Circle [Step] ( x, y), radius, [color, [start, end, [aspect]]]


Here are the arguments you pass to Circle:

•  Step—Keyword specifying that the center of the circle, ellipse, or arc is relative to the current coordinates given by the CurrentX and CurrentY properties of object.
•  x, y—Single values indicating the coordinates for the center point of the circle, ellipse, or arc. The ScaleMode property of object determines the units of measure used.
•  radius—Single value indicating the radius of the circle, ellipse, or arc. The ScaleMode property of object determines the unit of measure used.
•  color—Long integer value indicating the RGB color of the circle’s outline. If omitted, the value of the ForeColor property is used. You can use the RGB function or QBColor function to specify the color.
•  start, end—Single-precision values. When an arc or a partial circle or ellipse is drawn, start and end specify (in radians) the beginning and end positions of the arc. The range for both is –2 pi radians to 2 pi radians. The default value for start is 0 radians; the default for end is 2 * pi radians.
•  aspect—Single-precision value indicating the aspect ratio of the circle. The default value is 1.0, which yields a perfect (nonelliptical) circle on any screen.

Here’s how it works: the aspect ratio is the ratio of the vertical to horizontal axes in the ellipse, and the length of the ellipse’s 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 we’re drawing ellipses in Visual Basic.


Figure 18.7   Drawing ellipses with Visual Basic.
Drawing Arcs
You 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:

•  Step—Keyword specifying that the center of the circle, ellipse, or arc is relative to the current coordinates given by the CurrentX and CurrentY properties of object.
•  x, y—Single values indicating the coordinates for the center point of the circle, ellipse, or arc. The ScaleMode property of object determines the units of measure used.
•  radius—Single value indicating the radius of the circle, ellipse, or arc. The ScaleMode property of object determines the unit of measure used.
•  color—Long integer value indicating the RGB color of the circle’s outline. If omitted, the value of the ForeColor property is used. You can use the RGB function or QBColor function to specify the color.
•  start, end—Single-precision values. When an arc or a partial circle or ellipse is drawn, start and end specify (in radians) the beginning and end positions of the arc. The range for both is –2 pi radians to 2 pi radians. The default value for start is 0 radians; the default for end is 2 * pi radians.
•  aspect—Single-precision value indicating the aspect ratio of the circle. The default value is 1.0, which yields a perfect (nonelliptical) circle on any screen.

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).

Let’s 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 we’re drawing arcs in Visual Basic.


Figure 18.8   Drawing ellipses in forms and picture boxes.
The code for this example is located in the drawarcs 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:
596 599
YAMAHA AX 596
596 (2)
599 604
YAMAHA CDX 596
20080311 NMR2id&596
594 596
599,14,artykul
59903
59915
59905
59604
59916

więcej podobnych podstron