• There are several DLL routines that support graphic
methods. The DLL function Ellipse allows us to draw an ellipse bounded by a pre-defined
rectangular region.
• The Declare statement for the Ellipse function is:
Private Declare Function Ellipse Lib "gdi32"
Alias "Ellipse" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long,
ByVal X2 As Long, ByVal Y2 As Long) As Long
Note there are five arguments: hdc is the hDC handle for the
region (Form or Picture Box) being drawn to, (X1, Y1) define the upper left hand
corner of the rectangular region surrounding the ellipse and (X2,Y2) define the
lower right hand corner. The region drawn to must have its ScaleMode property
set to Pixels (all DLL drawing routine use pixels for coordinates).
• Any ellipse drawn with this routine is drawn using
the currently selected DrawWidth and ForeColor properties and filled according
to FillColor and FillStyle.
Quick Example
3 - Drawing Ellipses
-
Start a new application. Set the form’s ScaleMode property to Pixels.
-
Use the API Text Viewer to obtain the Declare statement for the Ellipse function
and copy it into the General Declarations area:
Option Explicit
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal
X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
-
Attach the following code to the Form_Resize event:
Private Sub Form_Resize()
Dim RtnValue As Long
Form1.Cls
RtnValue = Ellipse(Form1.hdc, 0.1 * ScaleWidth, 0.1 * ScaleHeight, 0.9 * ScaleWidth,
0.9 * ScaleHeight)
End Sub
-
Run the application. Resize the form and see how the drawn ellipse takes on
new shapes. Change the form’s DrawWidth, ForeColor, FillColor, and FillStyle
properties to obtain different styles of ellipses.