我要在VB里的一张图片跟着鼠标移动而移动,但用mousemove图片总会卡住,不那么灵活....还有其它方法没??
2个回答
展开全部
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
已发到邮箱
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
已发到邮箱
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询