Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

Draw a curve on form using Graphics class in - C

Author: Maliha Atteeq
Download Source Code :

In this simple article you will learn that how to draw curve on the form using Graphics class in vb and C


This is the very important class for making graphics of your own using c#. This class cannot be inherited. This class provides us a number of different methods for graphics creation. By using these methods you can create graphics of your own choice.

In this article I will tell you that how can we draw curve using

Curve draw:

In order to draw curve on the form, firstly you should know the behavior of the form. While playing with the graphics you must keep the following point in your mind:

You can’t draw graphics on simple load event of the form. To create graphics on the form, you must override the onpaint() function of the form.

The syntax of the onpaint() function is:


protected override void OnPaint (PaintEventArgs e)




Dim e As PaintEventArgs



Curve’s draw function:

In order to draw a curve, graphics class provides us a function named as drawCurve(). It is an overloaded function. By using this function you can draw curve on the form. Depending on your requirement you can use any of the overloaded function. I use the following:

This function takes two arguments. The first argument is the object of Pen class. Pen class has the four overloaded constructor. You can use any of the constructors to initialize the object of pen class. I use the following:


System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black);


Dim pen As New System.Drawing.Pen(System.Drawing.Color.Black)


The second argument is an array of point class. This class also provides us four overloaded constructor, depending on your requirement you can use any of them. I use the following constructor. This constructor takes two arguments as an parameter which are x,y coordinate.  All these are of type int.


System.Drawing.Point[] points = new Point[5];

            points[0] = new Point(75, 35);

            points[1] = new Point(85, 35);

            points[2] = new Point(45, 95);

            points[3] = new Point(65, 25);

            points[4] = new Point(65, 55);


Dim points As System.Drawing.Point() = New Point(5) {}

        points(0) = New Point(75, 35)

        points(1) = New Point(85, 35)

        points(2) = New Point(45, 95)

        points(3) = New Point(65, 25)

        points(4) = New Point(65, 55)


Pass all these arguments in the DrawCurve() function provided by the graphics class. Once you do this then you have to call the Dispose() method to epose your created arc. The dispose() function takes no argument as a paameter. This function simply expose your graphics on the form. You have to call this function with the object of graphics and also with the object of pen class.








To demonstrate make a new window application and write the following code on form’s onpaint event:


protected override void OnPaint(PaintEventArgs e)


            System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Coral);

            System.Drawing.Graphics obj;

            obj = this.CreateGraphics();

            System.Drawing.Point[] points = new Point[5];

            points[0] = new Point(35, 75);

            points[1] = new Point(25, 95);

            points[2] = new Point(45, 85);

            points[3] = new Point(55, 78);

            points[4] = new Point(65, 25);

            System.Drawing.SolidBrush brush = new SolidBrush(Color.DodgerBlue);

            obj.DrawCurve(pen, points);




Protected Overloads Overrides Sub OnPaint(ByVal e As PaintEventArgs)

        Dim pen As New System.Drawing.Pen(System.Drawing.Color.Coral)

        Dim obj As System.Drawing.Graphics

        obj = Me.CreateGraphics()

        Dim points As System.Drawing.Point() = New Point(5) {}

        points(0) = New Point(35, 75)

        points(1) = New Point(25, 95)

        points(2) = New Point(45, 85)

        points(3) = New Point(55, 78)

        points(4) = New Point(65, 25)

        Dim brush As System.Drawing.SolidBrush = New SolidBrush(Color.DodgerBlue)

        obj.DrawCurve(pen, points)


    End Sub


Now write the following code on FORM LOAD event:


private void Form1_Load(object sender, EventArgs e)


            this.Text = "DEVASP CURVE DRAW APPLICATION";




Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)



    End Sub

This simple article tells that how to draw curve using Graphics class in vb and C

Add Article Comment:
Name :
Email Address :
Comments :
<< Draw a filled ellipse on form using Graphics class in - C

Disclaimer - Privacy
© 2002-2017