第二次单击时未调用鼠标按下事件

时间:2012-07-11 21:22:59

标签: vb6 mouseevent picturebox

我有一个应用程序,我在图片框上画一条线/正方形。我还需要用户点击图片框上的特定点(绘制正方形/线后)以获得第二个点的位置。但鼠标按下事件不适用于第二次单击。我的代码如下所示:

Dim m_Drawing As Boolean
'm_Drawing = False
Dim m_Startx As Single
Dim m_Starty As Single
Dim m_endx As Single
Dim m_endy As Single
Dim square_click As Boolean
'square_click = False
Dim line_click As Boolean
'line_click = False
Dim bclick As Boolean
'blick = True
Dim startx As Single
Dim starty As Single
Dim endx As Single
Dim endy As Single
Dim laserx_mm As Single
Dim lasery_mm As Single
Dim rectx_mm As Single
Dim recty_mm As Single
Dim xpos As Single
Dim ypos As Single
Dim uxpos As Single
Dim uypos As Single
Dim dist As Single
Dim dist1 As Single

Private Sub Command1_Click()
square_click = True
End Sub

Private Sub Command2_Click()
line_click = True
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim diffx As Single
Dim diffy As Single

Picture1.Cls
If m_Startx = 0 And m_Starty = 0 Then
m_Startx = X
m_Starty = Y
'End If
startx = X
starty = Y
rectx_mm = X
recty_mm = Y
'move to start position
ElseIf m_Startx <> 0 And m_Starty <> 0 Then
laserx_mm = X
lasery_mm = Y

diffx = rectx_mm - laserx_mm
diffy = recty_mm - lasery_mm

dist = xpos + (diffx / 4.74 / 1000)
dist1 = ypos - (diffy / 4.68 / 1000)

End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
endx = X
endy = Y
m_endx = X
m_endy = Y
If square_click = True Then
Picture1.Line (m_Startx, m_Starty)-(endx, endy), vbWhite, B
ElseIf line_click = True Then
Picture1.Line (m_Startx, m_Starty)-(endx, endy), vbWhite
End If
End Sub

守则:ElseIf m_Startx <> 0 And m_Starty <> 0

除非直到我在那里放置断点,否则

不会被执行。我不确定为什么会这样。请帮帮我!希望我足够清楚!感谢。

1 个答案:

答案 0 :(得分:1)

我在你的Debug.Print "Here I am"内投了一个ElseIf m_Startx <> 0 And m_Starty <> 0电话......就像第二次点击时的魅力一样。也许你可能想要使用更深的颜色或更粗的线?白线很难看到。