Create one label, put it in the lower right-hand corner of the form, and change its (Name) property to "lblMode". Make the caption initially blank (it actually doesn't matter, as the caption will be overwritten as soon as the form loads).
In (General) (Declarations):
Dim DrawingMode As Integer Dim a1 As Integer Dim b1 As Integer Dim a2 As Integer Dim b2 As Integer Dim r As Integer |
Create a new procedure called DisplayDrawingMode (with the Code Windows showing, click the Tools drop-down menu, select Add Procedure, type "DisplayDrawingMode" and hit ENTER, leaving all the settings as they are) and put the following code into it:
If DrawingMode = 1 Then lblMode.Caption = "Freeform" ElseIf DrawingMode = 2 Then lblMode.Caption = "Line" ElseIf DrawingMode = 3 Then lblMode.Caption = "Box" Else ' DrawingMode = 4 lblMode.Caption = "Circle" End If |
In the Form's Load procedure (Form_Load):
DrawingMode = 1 DisplayDrawingMode |
In the Form's MouseDown procedure:
a1 = X b1 = Y r = 0 |
In the Form's MouseUp procedure:
If Button = 2 Then ' Clicked right mouse button DrawingMode = DrawingMode + 1 ' Next drawing mode If DrawingMode > 4 Then DrawingMode = 1 DisplayDrawingMode End If |
In the Form's MouseMove procedure:
If Button = 1 Then
If DrawingMode = 1 Then ' Freeform
Line (a1, b1)-(X, Y)
a1 = X
b1 = Y
ElseIf DrawingMode = 2 Then ' Line
Line (a1, b1)-(a2, b2), Form1.BackColor ' Erase old line
a2 = X ' Update values of a2 and b2
b2 = Y
Line (a1, b1)-(a2, b2) ' Draw new line
ElseIf DrawingMode = 3 Then ' Box
Line (a1, b1)-(a2, b2), Form1.BackColor, B
a2 = X
b2 = Y
Line (a1, b1)-(a2, b2), , B
Else ' DrawingMode = 4 Circle
Circle (a1, b1), r, Form1.BackColor
If Abs(X - a1) > Abs(Y - b1) Then ' If moved farther horizontally
r = Abs(X - a1) ' Radius = horizontal movement
Else ' Otherwise
r = Abs(Y - b1) ' Radius = vertical movement
End If
Circle (a1, b1), r
End If
End If
|
Note the following table of possible values for Button:
| Value | Meaning |
| 0 | No buttons are pressed |
| 1 | The left button caused the event |
| 2 | The right button caused the event |
| 3 | The left and right buttons caused the event |
| 4 | The middle button caused the event |
| 5 | The left and middle buttons caused the event |
| 6 | The right and middle buttons caused the event |
| 7 | All three buttons caused the event |
Extra Improvements:
CommonDialog1.ShowColor), then get its Color property and use that as the color to use when drawing.