Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDraw ellipses by specifying their bounding boxes
Keywordsellipse, bound, box, bounding box
CategoriesGraphics
 
Drawing ellipses with the Circle method is a bit counterintuitive. You need to specify the center of the ellipse, the longer of its two radii, and its aspect ratio (ratio of height to width).

Subroutine DrawEllipse lets you specify an ellipse by giving its bounding box. It calculates the center of the ellipse, the radius it needs to specify, and the aspect ratio needed to place the ellipse inside the bounding box.

 
' Draw an ellipse in the indicated rectangle.
Private Sub DrawEllipse(ByVal obj As Object, ByVal xmin As _
    Single, ByVal ymin As Single, ByVal xmax As Single, _
    ByVal ymax As Single)
Dim dx As Single
Dim dy As Single
Dim r As Single

    dx = xmax - xmin
    dy = ymax - ymin
    If dx > dy Then
        r = dx / 2
    Else
        r = dy / 2
    End If
    obj.Circle ((xmin + xmax) / 2, (ymin + ymax) / 2), r, , _
        , , dy / dx
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated