VB中画直线问题?

我在picture2控件中画直线,单击起点并按住拖动鼠标时到终点松开可画出一条直线,双击起点第二下不松开并拖动鼠标时会画同以起点开始的N多条直线,请问该如何改,见程序Pr... 我在picture2控件中画直线,单击起点并按住拖动鼠标时到终点松开可画出一条直线,双击起点第二下不松开并拖动鼠标时会画同以起点开始的N多条直线,请问该如何改,见程序
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
Picture2.AutoRedraw = False
startx = X '记住起始点
starty = Y
End Sub

Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
Picture2.Refresh
Picture2.Line (startx, starty)-(X, Y) '显示橡皮筋效果
End Sub

Private Sub Picture2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
endx = X '记住终止点
endy = Y
Picture2.AutoRedraw = True
Picture2.Line (startx, starty)-(endx, endy) '最终画线
End Sub
展开
 我来答
KL1112
2011-08-02 · TA获得超过532个赞
知道小有建树答主
回答量:454
采纳率:0%
帮助的人:628万
展开全部
“双击起点第二下不松开并拖动鼠标时会画同以起点开始的N多条直线”,这是程序的响应事件问题,第一次MouseDown、MouseUp,再按下时,就产生DblClick事件,同时阻断MouseDown事件,再松开时,就产生MouseUp事件。(需要按同一个键)
DblClick事件只需要MouseDown、MouseUp、MouseDown就会产生。
可以这么说,DblClick事件替换掉了第二次的MouseDown事件。

只要在DblClick事件里调用MouseDown事件就能解决问题了。

添加一个变量
Dim Bn As Integer '记录按键信息

Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Bn = Button
If Button <> 1 Then Exit Sub
Picture2.AutoRedraw = False
startx = X
starty = Y
End Sub

Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
Picture2.Refresh
Picture2.Line (startx, starty)-(X, Y)
End Sub

Private Sub Picture2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
endx = X
endy = Y
Picture2.AutoRedraw = True
Picture2.Line (startx, starty)-(endx, endy)
End Sub

Private Sub Picture2_DblClick()
If Bn = 1 Then Call Picture2_MouseDown(1, 0, endx, endy)
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式