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
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
已发到邮箱