|
|
Title | Make a scribble application with VB .NET |
Keywords | VB.NET, drawing, scribble |
Categories | Graphics, VB.NET |
|
|
In the MouseDown event handler, set m_Drawing to True and save the current point.
In the MouseMove event handler, verify that m_Drawing is True. If it is, draw a line from the previously saved point to the current point. Then save the new current point.
In the MouseUp event handler, set m_Drawing to False.
|
|
Private m_Drawing As Boolean
Private m_LastX As Integer
Private m_LastY As Integer
' Start scribbling.
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs) Handles _
MyBase.MouseDown
m_Drawing = True
m_LastX = e.X
m_LastY = e.Y
End Sub
' Continue scribbling.
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs) Handles _
MyBase.MouseMove
If m_Drawing Then
Me.CreateGraphics().DrawLine(Pens.Black, m_LastX, _
m_LastY, e.X, e.Y)
m_LastX = e.X
m_LastY = e.Y
End If
End Sub
' Stop scribbling.
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs) Handles _
MyBase.MouseUp
m_Drawing = False
End Sub
|
|
Note that this program draws directly on the form's surface and the drawing is not saved anywhere. If you cover the form and then expose it, the drawing is lost.
|
|
|
|
|
|