VB.NET 1.1 Tutorial - GDI+ - Part 3 - ArcsIn this part we will look at some simple applications that utilise the method DrawArc. Arcs with RectanglesThe first two versions of the DrawArc method we shall look at, takes four parameters. The syntax for the method definition is: Public Sub DrawArc( _ ByVal pen As Pen, _ ByVal rect As Rectangle, _ ByVal startAngle As Single, _ ByVal sweepAngle As Single _ ) or Public Sub DrawArc( _ ByVal pen As Pen, _ ByVal rect As RectangleF, _ ByVal startAngle As Single, _ ByVal sweepAngle As Single _ ) Where the Parameters are:
These methods draw an arc that is a portion of the perimeter of an ellipse. The ellipse is defined by the boundaries of a rectangle. The arc is the portion of the perimeter of the ellipse between the startAngle parameter and the startAngle + sweepAngle parameters. We will create a simple example to draw an arc on the form. Private Sub ArcDemo_Paint( ByVal sender As Object, _
ByVal e As PaintEventArgs) _
Handles MyBase.Paint
' Get Graphics Object
Dim g As Graphics = e.Graphics
' Create Pen
Dim myPen As New Pen( Color.Blue, 2 )
' Create rectangle to bound arc.
Dim rect As New Rectangle( 30, 30, 200, 100)
' Create start and sweep angles on arc.
Dim startAngle As Integer = 45
Dim sweepAngle As Integer = 180
' Draw arc to screen.
g.DrawArc( myPen, rect, startAngle, sweepAngle)
' Now tidy up
myPen.Dispose()
End Sub
This code gives the following output: ![]() You can download the file arc01.vb from the link, or you can download my copy of the executable from here. Arcs with valuesThe other two methods just use integers or floating point values to define the parameters. Public Sub DrawArc( _ ByVal pen As Pen, _ ByVal x As Integer, _ ByVal y As Integer, _ ByVal width As Integer, _ ByVal height As Integer, _ ByVal startAngle As Integer, _ ByVal sweepAngle As Integer _ ) or Public Sub DrawArc( _ ByVal pen As Pen, _ ByVal x As Single, _ ByVal y As Single, _ ByVal width As Single, _ ByVal height As Single, _ ByVal startAngle As Single, _ ByVal sweepAngle As Single _ ) Where the Parameters are:
Arcs with StyleBefore we leave arcs, I thought we would show that the DashStyle Enumeration can be applied to arcs as well as lines. The screen shot below shows arcs with different styles. ![]() You can download the file arc02.vb from the link, or you can download my copy of the executable from here. ReferencesFor more information on the DrawArc Method, visit MSDN at microsoft here. For more information on the DashStyle Enumeration, visit MSDN at microsoft here. What Next?Next we will draw some simple Rectangles. Return to the Tutorial Contents. |