CST2601 Visual
Basic I
Notes on Circle
Circle MethodDraws a circle, ellipse, or arc on an object. Syntax object.Circle [Step] (x, y), radius, [color, start, end, aspect] The Circle method syntax has the following object qualifier and parts:
Remarks To fill a circle, set the FillColor and FillStyle properties of the object on which the circle or ellipse is drawn. Only a closed figure can be filled. Closed figures include circles, ellipses, or pie slices (arcs with radius lines drawn at both ends). When drawing a partial circle or ellipse, if start is negative, Circle draws a radius to start, and treats the angle as positive; if end is negative, Circle draws a radius to end and treats the angle as positive. The Circle method always draws in a counter-clockwise (positive) direction. The width of the line used to draw the circle, ellipse, or arc depends on the setting of the DrawWidth property. The way the circle is drawn on the background depends on the setting of the DrawMode and DrawStyle properties. When drawing pie slices, to draw a radius to angle 0 (giving a horizontal line segment to the right), specify a very small negative value for start, rather than zero. You can omit an argument in the middle of the syntax, but you must include the argument's comma before including the next argument. If you omit an optional argument, omit the comma following the last argument you specify. When Circle executes, the CurrentX and CurrentY properties are set to the center point specified by the arguments. This method cannot be used in an With…End With block. Circle Method ExampleThis example uses the Circle method to draw a number of concentric circles in the center of a form. To try this example, paste the code into the General section of a form. Then press F5 and click the form.
Drawing CirclesThe Circle method draws a variety of circular and elliptical (oval) shapes. In addition, Circle draws arcs (segments of circles) and pie-shaped wedges. You can produce many kinds of curved lines using variations of the Circle method. To draw a circle, Visual Basic needs the location of a circle’s center and the length of its radius. The syntax for a perfect circle is: [object.]Circle [Step](x, y), radius[, color] The brackets indicate that both object and the Step keyword are optional. If you don’t specify object, the current form is assumed. The x and y arguments are the coordinates of the center, and radius is the radius of the circle. For example, this statement draws a circle with a center at (1200, 1000) and radius of 750:
The exact effect of this statement depends on the size and coordinate system of the form. Because the size of the form is unknown, you don’t know if the circle will be visible. Using the drawing area’s scale properties puts the center of the circle at the center of the form:
For now, all you need to know about ScaleWidth and ScaleHeight is that they help position graphics in the center of a form. For More Information "Changing an Object’s Coordinate System" earlier in this chapter discusses the ScaleWidth and ScaleHeight properties in detail. Note The radius of the circle is always specified in terms of horizontal units. If your coordinate system uses the same horizontal and vertical units (which it does by default), you can ignore this fact. However, if you use a custom scale, horizontal and vertical units may correspond to different distances. In the preceding examples, the radius is specified in horizontal units, and the actual height of the circle is guaranteed to be equal to its actual width. The Blanker application creates circles as part of the Rainbow Rug demo. This demo draws a series of dashed line circles around the center of the form. In time the circles resemble a woven circular rug. The CircleDemo procedure creates the circles in the Rainbow Rug demo with the following statements:
The results of the Rainbow Rug demo are shown in Figure 12.16. Figure 12.16 The Rainbow Rug demo in the Blanker application Drawing ArcsTo draw arcs with the Circle method, you need to give angle arguments in radians to define the start and the end of the arc. The syntax for drawing an arc is: [object.]Circle [Step](x, y), radius, [color], start, end[, aspect] If the start or end argument is negative, Visual Basic draws a line connecting the center of the circle to the negative end point. For example, the following procedure draws a pie with a slice removed.
Note The formula for converting from degrees to radians is to multiply degrees by Pi/180. |