By using an alternate event when a line is drawn, we can achieve a better result. The MouseMove event can be used to draw curves with the same code as before. PicDraw1.Line (X,Y). This event has the facility to determine which mouse button is pressed when the mouse is being moved, so we can make it draw only when a mouse button is held down. The code is simple as … If Button = 1 then (draw the line).
This still has the problem in that the line starts from the top corner (0,0) and it would be good if it would start from where we want it. The properties CurrentX and CurrentY can be set with a MouseDown event. Thus the line can start and end where we like.
The code segment is as follows.
PicDraw1.CurrentX = X
PicDraw1.CurrrentY = Y

This program has only two objects. A command button to clear the picture and a picture. The picture is drawn by moving the mouse.
Code
Private Sub CmdClear_Click()
PicDraw.Cls
End Sub
Private Sub PicDraw_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
PicDraw.CurrentX = X ' sets the starting position of line PicDraw.CurrentY = Y
End Sub
Private Sub PicDraw_MouseMove(Button As Integer,Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
PicDraw.Line -(X, Y) ' draw a line to (x,y)
End If
End Sub
Hint - circles can be drawn using the following.
General
Dim Xstart As Single
Dim Ystart As Single
Private Sub PicDraw_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
PicDraw.Circle (Xstart, Ystart), Sqr((X - Xstart) ^ 2 + (Y - Ystart) ^ 2) ' Get the radius using Pythagoras
End Sub
Private Sub PicDraw_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Xstart = X
Ystart = Y
End Sub
Author: Mike Leishman
Created : June 28 1998