'干脆帮你把取消划线的功能也做了,按鼠标右键即可取消你画的线,而按左键即可划线
Dim startX As Single, startY As Single
Dim drawing As Boolean
Dim oldX As Single, oldY As Single
Dim arrayLine(100, 3) As Single, lineCount As Integer
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 100
arrayLine(i, 0) = -1
Next
lineCount = 0
drawing = False
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
drawing = drawing Xor True
If drawing Then
Form1.MousePointer = 2
startX = X
startY = Y
oldX = X
oldY = Y
Else
Form1.MousePointer = 0
arrayLine(lineCount, 0) = startX
arrayLine(lineCount, 1) = startY
arrayLine(lineCount, 2) = oldX
arrayLine(lineCount, 3) = oldY
lineCount = lineCount + 1
End If
End If
If Button = 2 And drawing Then
Form1.Line (startX, startY)-(oldX, oldY), Me.BackColor
drawing = False
Form1.MousePointer = 0
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Integer
If drawing Then
Form1.Line (startX, startY)-(oldX, oldY), Me.BackColor
For i = 0 To 100
If arrayLine(i, 0) < 0 Then Exit For
Form1.Line (arrayLine(i, 0), arrayLine(i, 1))-(arrayLine(i, 2), arrayLine(i, 3)), &HFF
Next
Form1.Line (startX, startY)-(X, Y), &HFF
oldX = X
oldY = Y
End If
End Sub