Visual Basic > Graphics Games Programming
Creating a Freehand Drawing Tool
Creating a Freehand Drawing Tool 'Variables used for the drawing tool. Dim Drawing As Boolean Dim FHLastX As Long Dim FHLastY As Long Private Sub Picture1_MouseDown(Button As Integer, _ Shift As Integer, X As Single, Y As Single) 'Specify that we are drawing now. Drawing = True 'Start where the mouse cursor is. FHLastX = X FHLastY = Y End Sub Private Sub Picture1_MouseMove(Button As Integer, _ Shift As Integer, X As Single, Y As Single) 'This is the technique we are using to 'draw freehand decently. Instead of drawing each point, 'we join the points up with lines. This is required as the 'MouseMove event will not fire on every pixel. Picture1.Line (FHLastX, FHLastY)-(X, Y) FHLastX = X FHLastY = Y End Sub Private Sub Picture1_MouseUp(Button As Integer, _ Shift As Integer, X As Single, Y As Single) 'Stop drawing. Drawing = False End Sub
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows