VB如何实现图片在某一区域移动?
2个回答
展开全部
拉一个pictuerbox然后点击的时候它就会跟鼠标一起动再点的时候就会停下来
,就实现了你说的效果.要拉一个timer控件.
Dim k As Integer
Private Sub Form_Load()
k = 0
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Timer1.Enabled = True And k Mod 2 <> 0 Then
Picture1.Left = X - 250
Picture1.Top = Y - 250
Else
Timer1 = False
End If
End Sub
Private Sub Picture1_Click()
Timer1.Enabled = True
k = k + 1
End Sub
以下是限定图片移动范围,比如要让他在5000*5000范围内移动就按以下输入.
注:如果移动范围是5000*5000则窗体的大小应该是 5000+图片宽度*5000+图片高,比如图片是100*100限定范围是3000*3000则窗体大小为3100*3100,如果每个图片不一样大则只要更改单个图片的移动范围就可以达到完美效果.
Private Sub Timer1_Timer()
If Picture1.Left <= 0 Then
Picture1.Left = 0
End If
If Picture1.Left >= 5000 Then
Picture1.Left = 5000
End If
If Picture1.Top <= 0 Then
Picture1.Top = 0
End If
If Picture1.Top >= 5000 Then
Picture1.Top = 5000
End If
End Sub
,就实现了你说的效果.要拉一个timer控件.
Dim k As Integer
Private Sub Form_Load()
k = 0
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Timer1.Enabled = True And k Mod 2 <> 0 Then
Picture1.Left = X - 250
Picture1.Top = Y - 250
Else
Timer1 = False
End If
End Sub
Private Sub Picture1_Click()
Timer1.Enabled = True
k = k + 1
End Sub
以下是限定图片移动范围,比如要让他在5000*5000范围内移动就按以下输入.
注:如果移动范围是5000*5000则窗体的大小应该是 5000+图片宽度*5000+图片高,比如图片是100*100限定范围是3000*3000则窗体大小为3100*3100,如果每个图片不一样大则只要更改单个图片的移动范围就可以达到完美效果.
Private Sub Timer1_Timer()
If Picture1.Left <= 0 Then
Picture1.Left = 0
End If
If Picture1.Left >= 5000 Then
Picture1.Left = 5000
End If
If Picture1.Top <= 0 Then
Picture1.Top = 0
End If
If Picture1.Top >= 5000 Then
Picture1.Top = 5000
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询