我要在VB里的一张图片跟着鼠标移动而移动,但用mousemove图片总会卡住,不那么灵活....还有其它方法没??

 我来答
swx1995
2009-04-23 · TA获得超过2696个赞
知道大有可为答主
回答量:1477
采纳率:0%
帮助的人:2363万
展开全部
1.
把图片左、上留下一些透明区域。这些透明区域就作为了感应区域。这样可以减小卡住几率。毕竟鼠标经过它们不触发事件不大现实。

2.
干脆用API,timer不断获取鼠标坐标 然后调整位置(最好记录下上次位子,如果不同则移动。
百度网友e9042513a
2009-04-23 · TA获得超过6984个赞
知道大有可为答主
回答量:2388
采纳率:0%
帮助的人:3509万
展开全部
Dim DownX As Integer
Dim DownY As Integer

Private Sub Form_Load()
Me.ScaleMode = 3
Picture1.ScaleMode = 3
Picture1.Picture = LoadPicture("c:\my documents\005.jpg") '要装入的图片
DownX = -1

End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
DownX = X
DownY = Y
End If

End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim l As Integer
Dim t As Integer
Dim dx As Integer
Dim dy As Integer

If (Button And 1) = 1 Then
dx = X - DownX
dy = Y - DownY
If (dx < 0 And Picture1.Left = 0) Or (dx > 0 And Picture1.Left + Picture1.Width = ScaleWidth) Then
DownX = X
Else
l = Picture1.Left + dx
If l < 0 Then
l = 0
ElseIf l + Picture1.Width > ScaleWidth Then
l = ScaleWidth - Picture1.Width
End If
Picture1.Left = l
End If
If (dy < 0 And Picture1.Top = 0) Or (dy > 0 And Picture1.Top + Picture1.Height = ScaleHeight) Then
DownY = Y
Else
t = Picture1.Top + dy
If t < 0 Then
t = 0
ElseIf t + Picture1.Height > ScaleHeight Then
t = ScaleHeight - Picture1.Height
End If
Picture1.Top = t
End If
End If

End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then DownX = -1

End Sub

已发到邮箱
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式