Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Graphics Games Programming Code Examples

Creating a Freehand Drawing Tool

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
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