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 PATHS on Form which follows your mouse using System.Drawing.Drawing2D.GraphicsPath in VB.Net

Author: DevASP
Download Source Code : 502_DRAW_PATH.zip

In this simple article you will learn that how you can draw PATHS on Form which follows your mouse using System.Drawing.Drawing2D.GraphicsPath which follows your mouse.

Create New Project of windows application in VB and drag two labels and a timer on form.

 

Is create some global variables

 

    Dim x1 As Integer = 10

    Dim x2 As Integer = 10

    Dim y1 As Integer = 50

    Dim y2 As Integer = 50

Now write code in following events:

 

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

        Me.BackColor = Color.LightGoldenrodYellow

        Me.WindowState = FormWindowState.Maximized

 

        Me.Text = "DevAsp"

        Label1.Location = New System.Drawing.Point(Me.Width / 2 - Label1.Width / 2, 50)

        Label2.Location = New System.Drawing.Point(Me.Width / 2 - Label1.Width / 2, 150)

 

End Sub

 

 

 

Private Sub Form2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

 

        Dim myPen As Pen

        myPen = New Pen(Color.MediumSeaGreen, 58)

        Dim gr As System.Drawing.Graphics = e.Graphics

        Dim path As System.Drawing.Drawing2D.GraphicsPath

        Dim pt(6) As Point

        pt(0).X = Me.MousePosition.X

        pt(0).Y = Me.MousePosition.X

        pt(1).X = Me.MousePosition.X

        pt(1).Y = Me.MousePosition.Y

        pt(2).X = Me.MousePosition.Y

        pt(2).Y = Me.MousePosition.Y

        pt(3).X = Me.MousePosition.Y

        pt(3).Y = Me.MousePosition.X

        pt(4).X = Me.MousePosition.Y + 300

        pt(4).Y = Me.MousePosition.Y + 100

        pt(5).X = Me.MousePosition.Y + 200

        pt(5).Y = Me.MousePosition.X + 40

 

        path = New System.Drawing.Drawing2D.GraphicsPath(Drawing2D.FillMode.Alternate)

        path.AddLines(pt)

        path.CloseAllFigures()

        gr.DrawPath(myPen, path)

        Timer1.Start()

 

End Sub

 

 

 

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

 

        Me.BackColor = Color.LightGray

        Me.BackColor = Color.LightGreen

        Me.BackColor = Color.LightGray

 

End Sub

 

 

 

Private Sub Form2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

 

        If e.Button = MouseButtons.Left Then

            Timer1.Stop()

        End If

        If e.Button = MouseButtons.Right Then

            Timer1.Start()

        End If

 

End Sub

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Creating an Images Using Mouse in Visual Basic.Net

Disclaimer - Privacy
© 2002-2017 DevASP.net