Public x1, y1, i, c As Integer 'i为绘画标志,c为绘画完成后的清屏标志
Public newX, newY, oldX, oldY As Integer 'oldX,oldY为最初的点坐标,newX,newY为最后一次的坐标定位
Private Sub Form_DblClick()
Form1.AutoRedraw = True
Line (oldX, oldY)-(newX, newY) '双击闭合曲线
i = 0
c = 1
End Sub
Private Sub Form_Load()
i = 0
c = 0
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If c = 1 Then
Form1.Cls
c = 0
End If
PSet (X, Y) '画初点
x1 = X
y1 = Y
i = i + 1 '设置初始标志
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 0 Then '如果无鼠标键按下,画线
If i >= 2 Then '过程画线
Form1.AutoRedraw = False
Form1.Refresh
Line (newX, newY)-(X, Y)
End If
If i = 1 Then '初次画线
Form1.AutoRedraw = False
Form1.Refresh
Line (x1, y1)-(X, Y)
oldX = x1
oldY = y1
i = i + 1
End If
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'画下最终确定的直线
If i = 1 Then '初次画线
Me.DrawMode = 13
Me.AutoRedraw = True
Line (x1, y1)-(X, Y)
newX = X
newY = Y
End If
If i >= 2 Then '过程画线
Me.DrawMode = 13
Me.AutoRedraw = True
Line (newX, newY)-(X, Y)
newX = X
newY = Y
End If
End Sub