现在打算完成利用鼠标完成绘画功能,程序编制如下:以划线为例,程序如下:
Dim ax, ay, px, py As SinglePrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then ax = X:ay = Y:px = X:py = Y
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Picture1.Line (ax, ay)-(X, Y)
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Picture1.Line (ax, ay)-(X, Y)
End Sub窗体上只有一个图片框,但是结果好像不对,请帮助修正,,并给予代码注释。此外,在划线过程中是否是mousedown 和mousemove事件同时触发。此外刚刚将程序作以修正如下:
Dim ax, ay, px, py As Single
Dim Temp As Integer
Private Sub Form_Load()
ax = 0
ay = 0
px = 0
py = 0
End Sub
Private Sub Option1_Click()
Temp = 1
End Sub
Private Sub Option2_Click()
Temp = 2
End Sub
Private Sub Option3_Click()
Temp = 3
End Sub
Private Sub Option4_Click()
Temp = 4
End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
ax = X
ay = Y
End If
If Temp = 4 Then
Picture1.CurrentX = X
Picture1.CurrentY = Y
End If
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)'前半部分
If Temp = 1 Then
Picture1.Line (ax, ay)-(px, py)
End If
If Temp = 2 Then
Picture1.Line (ax, ay)-(ax, py)
Picture1.Line (ax, ay)-(px, ay)
Picture1.Line (px, ay)-(px, py)
Picture1.Line (ax, py)-(px, py)
End If
If Temp = 3 Then
Picture1.Circle ((ax + px) / 2, (ay + py) / 2), 0.5 * Sqr((px - ax) ^ 2 + (py - ay) ^ 2)
End If'后半部分If Button = 1 Then
If Temp = 1 Then
Picture1.Line (ax, ay)-(X, Y)
px = X
py = Y
End If
If Temp = 2 Then
Picture1.Line (ax, ay)-(X, ay)
Picture1.Line (ax, ay)-(ax, Y)
Picture1.Line (ax, Y)-(X, Y)
Picture1.Line (X, ay)-(X, Y)
px = X
py = Y
End If
If Temp = 3 Then
Picture1.Circle ((ax + X) / 2, (ay + Y) / 2), 0.5 * Sqr((X - ax) ^ 2 + (Y - ay) ^ 2)
px = X
py = Y
End If
If Temp = 4 Then
Picture1.Line -(X, Y)
px = X
py = Y
End If
End If
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
If Temp = 1 Then
Picture1.Line (ax, ay)-(X, Y)
Else
If Temp = 2 Then
Picture1.Line (ax, ay)-(X, ay)
Picture1.Line (ax, ay)-(ax, Y)
Picture1.Line (ax, Y)-(X, Y)
Picture1.Line (X, ay)-(X, Y)
Else
If Temp = 3 Then
Picture1.Circle ((ax + X) / 2, (ay + Y) / 2), 0.5 * Sqr((X - ax) ^ 2 + (Y - ay) ^ 2)
End If
End If
End If
ax = 0
ay = 0
px = 0
py = 0
End If
End Sub在修改后的程序中将form_load事件注释,将mousemove事件中的前半部分注释,将mouseup事件中的ax=0:ay=0:px=0:py=0,也注释得到的结果也不对,另外,如果将程序中的form_load事件和ax=0:ay=0:px=0:py=0进行注释,会发现划线的结果和刚才一样!
希望你们的答复,谢谢!
Dim ax, ay, px, py As SinglePrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then ax = X:ay = Y:px = X:py = Y
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Picture1.Line (ax, ay)-(X, Y)
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Picture1.Line (ax, ay)-(X, Y)
End Sub窗体上只有一个图片框,但是结果好像不对,请帮助修正,,并给予代码注释。此外,在划线过程中是否是mousedown 和mousemove事件同时触发。此外刚刚将程序作以修正如下:
Dim ax, ay, px, py As Single
Dim Temp As Integer
Private Sub Form_Load()
ax = 0
ay = 0
px = 0
py = 0
End Sub
Private Sub Option1_Click()
Temp = 1
End Sub
Private Sub Option2_Click()
Temp = 2
End Sub
Private Sub Option3_Click()
Temp = 3
End Sub
Private Sub Option4_Click()
Temp = 4
End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
ax = X
ay = Y
End If
If Temp = 4 Then
Picture1.CurrentX = X
Picture1.CurrentY = Y
End If
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)'前半部分
If Temp = 1 Then
Picture1.Line (ax, ay)-(px, py)
End If
If Temp = 2 Then
Picture1.Line (ax, ay)-(ax, py)
Picture1.Line (ax, ay)-(px, ay)
Picture1.Line (px, ay)-(px, py)
Picture1.Line (ax, py)-(px, py)
End If
If Temp = 3 Then
Picture1.Circle ((ax + px) / 2, (ay + py) / 2), 0.5 * Sqr((px - ax) ^ 2 + (py - ay) ^ 2)
End If'后半部分If Button = 1 Then
If Temp = 1 Then
Picture1.Line (ax, ay)-(X, Y)
px = X
py = Y
End If
If Temp = 2 Then
Picture1.Line (ax, ay)-(X, ay)
Picture1.Line (ax, ay)-(ax, Y)
Picture1.Line (ax, Y)-(X, Y)
Picture1.Line (X, ay)-(X, Y)
px = X
py = Y
End If
If Temp = 3 Then
Picture1.Circle ((ax + X) / 2, (ay + Y) / 2), 0.5 * Sqr((X - ax) ^ 2 + (Y - ay) ^ 2)
px = X
py = Y
End If
If Temp = 4 Then
Picture1.Line -(X, Y)
px = X
py = Y
End If
End If
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
If Temp = 1 Then
Picture1.Line (ax, ay)-(X, Y)
Else
If Temp = 2 Then
Picture1.Line (ax, ay)-(X, ay)
Picture1.Line (ax, ay)-(ax, Y)
Picture1.Line (ax, Y)-(X, Y)
Picture1.Line (X, ay)-(X, Y)
Else
If Temp = 3 Then
Picture1.Circle ((ax + X) / 2, (ay + Y) / 2), 0.5 * Sqr((X - ax) ^ 2 + (Y - ay) ^ 2)
End If
End If
End If
ax = 0
ay = 0
px = 0
py = 0
End If
End Sub在修改后的程序中将form_load事件注释,将mousemove事件中的前半部分注释,将mouseup事件中的ax=0:ay=0:px=0:py=0,也注释得到的结果也不对,另外,如果将程序中的form_load事件和ax=0:ay=0:px=0:py=0进行注释,会发现划线的结果和刚才一样!
希望你们的答复,谢谢!
If Button = 1 Then
If Temp = 1 Then
Picture1.Cls
If Temp = 2 Then
Picture1.Cls
If Temp = 3 Then
Picture1.Cls