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

来源:百度知道 编辑:UC知道 时间:2024/06/21 19:34:25

1.
把图片左、上留下一些透明区域。这些透明区域就作为了感应区域。这样可以减小卡住几率。毕竟鼠标经过它们不触发事件不大现实。

2.
干脆用API,timer不断获取鼠标坐标 然后调整位置(最好记录下上次位子,如果不同则移动。

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