Visual Basic Reference
MouseMove Event Example
This example demonstrates a simple paint application. The MouseDown event procedure works with a related MouseMove event procedure to enable painting when any mouse button is pressed. The MouseUp event procedure disables painting. To try this example, paste the code into the Declarations section of a form, and then press F5 and click the form and move the mouse while the mouse button is pressed.
Dim PaintNow As Boolean ' Declare variable.
Private Sub Form_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
PaintNow = True ' Brush on.
End Sub
Private Sub Form_MouseUp (Button As Integer, X As Single, Y As Single)
PaintNow = False ' Turn off painting.
End Sub
Private Sub Form_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
If PaintNow Then
PSet (X, Y) ' Draw a point.
End If
End Sub
Private Sub Form_Load ()
DrawWidth = 10 ' Use wider brush.
ForeColor = RGB(0, 0, 255) ' Set drawing color.
End Sub