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

How to draw an arrow using Graphics class vb.net – C#.net.

Author: Shehzad Hemani
Download Source Code : 1078_source.zip

In this simple article you will learn that how we can do draw an arrow using Graphics and class vb.net – C#.net

 Arrow:

To draw an arrow first all create an object of Graphics class. After creating the object you will have to set the smoothing mode of the graphics. This is basically a rendering quality. There is a property of graphics class names smoothing mode. This property takes value of enumeration named smoothingmode. There are different types of smoothing mode but we will use AntiAlias.

After setting the rendering quality you will have to set the color of the client area or form. For this purpose we have a function of form class named FillRectangle (). This function takes two parameters one is object of brush class and other is the object of rectangle class.

Now create an object of pen class. Set the start cap of the pen using the property of pen class named startcap. This property takes value of enumeration named linecap. Now set the end cap using property of pen class named endcap. This property takes value of enumeration named linecap.

Now the draw the arrow using function of graphics class named drawline. This function takes 5 parameters. Four integers those tell the coordinates of the starting and ending of the arrow and an object of pen class.

Now write the following code on Form Paint Event.

C#

private void Paint_Event(object sender, PaintEventArgs e)

        {

            Graphics g = e.Graphics;

            int x1 = 30;

            int y1 = 3;

            int x2 = 80;

            int y2 = 30;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            g.FillRectangle(Brushes.White, this.ClientRectangle);

            Pen p = new Pen(Color.Black, 10);

            p.StartCap = LineCap.Round;

            p.EndCap = LineCap.ArrowAnchor;

            g.DrawLine(p, x1,y1,x2,y2);

            p.Dispose();

        }

VB

Private Sub Paint_Event(ByVal sender As ObjectByVal As PaintEventArgs)
        
Dim As Graphics e.Graphics
        
Dim x1 As Integer = 30
        
Dim y1 As Integer = 3
        
Dim x2 As Integer = 80
        
Dim y2 As Integer = 30
        
g.SmoothingMode SmoothingMode.AntiAlias
        g.FillRectangle(Brushes.White, 
Me.ClientRectangle)
        
Dim As Pen = New Pen(Color.Black, 10)
        p.StartCap 
LineCap.Round
        p.EndCap 
LineCap.ArrowAnchor
        g.DrawLine(p, x1, y1, x2, y2)
        p.Dispose
    
End Sub

This is simple code to draw an arrow.

Now write the following code on FORM LOAD event:

C#

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "Devasp Animation Application";

        }

VB

Private Sub Form1_Load(ByVal sender As ObjectByVal As EventArgs)
        
Me.Text "Devasp Animation Application"
End Sub

This simple article tells that how we can do draw an arrow using Graphics and class vb.net – C#.net

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Text rendering and single bit per pixel grid fit in VB - C #.net.

Disclaimer - Privacy
© 2002-2017 DevASP.net