首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

画图怎么处理鼠标,鼠标不能越界

2013-01-11 
画图怎样处理鼠标,鼠标不能越界本帖最后由 bcrun 于 2012-08-29 10:01:24 编辑比如在picturebox上画图形,

画图怎样处理鼠标,鼠标不能越界
本帖最后由 bcrun 于 2012-08-29 10:01:24 编辑 比如在picturebox上画图形,如果鼠标超过picturebox的范围,但是画得图不能出去,怎么处理?

Dim x1, y1 As Long
Private Sub Command1_Click()
Picture1.Cls
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button Then
x1 = x: y1 = y
End If
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)

If Button Then
Picture1.DrawWidth = 3
Picture1.Cls
Picture1.Circle (x1, y1), Sqr((x1 - x) ^ 2 + (y1 - y) ^ 2)
End If
End Sub

[解决办法]
加上判定试试啊


if X <= Picture1.width and Y <=  Picture1.height

Picture1.Circle (x1, y1), Sqr((x1 - x) ^ 2 + (y1 - y) ^ 2)

end if 
[解决办法]
超过picturebox的范围么, 就不存在咯. 好比你桌上一张白纸, 你拿笔在纸外面画画, 这纸上当然不会有痕迹.

如果有报错, 那么针对报错的地方改一下代码就可以啦.
[解决办法]
是的加越界判定语句就可以了。

热点排行