Mouse Move Paint

Submitted by:Andery Smith

Date added:01 March, 2011

Category:Visual Basic

Mouse Move Paint . A simple program for drawing using mouse move event in vb.net 2005 version...
This code is compatible with : VB 2005, VB 2008, VB 2010

Steps For Creation:-
---------------------------
1. Change the background color of the form1 as white.
2. Then, double click the form and change the event as mouse move click event.
3. Now, write the code given below.
4. Save all and run the form.

Tags: mouse paint , drawing using mouse move

Code Snippet:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Cursor = Cursors.Hand
End Sub

Dim shouldPaint As Boolean = False

Private Sub MouseEvent_MouseDown(ByVal sender As
Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Handles MyBase.MouseDown
shouldPaint = True
End Sub

Private Sub MouseEvent_MouseMove(ByVal sender As
Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Handles MyBase.MouseMove
If shouldPaint Then
Dim graphic As Graphics = CreateGraphics()
graphic.FillEllipse(New SolidBrush(Color.Magenta),
e.X, e.Y, 10, 5)
End If
End Sub

Private Sub MouseEvent_MouseUp(ByVal sender As
Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Handles MyBase.MouseUp
shouldPaint = False
End Sub
End Class
 
 

Comments