编写vb程序,让一张图片实现左右移动,碰壁反弹,带背景颜色
带背景的窗体里一个图片从右向左移动,碰壁弹回。。。就是这样。。!!!高手指教!DimIsPlayingAsBoolean'DimDetaXAsLong'PrivateSu...
带背景的窗体里一个图片从右向左移动,碰壁弹回。。。
就是这样。。!!!高手指教!
Dim IsPlaying As Boolean '
Dim DetaX As Long '
Private Sub Form_Load()
Form1.BackColor = RGV(*******) '
IsPlaying = False '
DetaX= -100
Image1.Left = 13300 '
end Sub
(下来一段是启动的描述)
再下来
Private Sub Timer1_Timer()
Image1.Move Image1.Left + DetaX
(注意:)If Image1.Left > Me.Midth Then '
Image1.left = 0
End If
End Sub
我是就DetaX= 100
Image1.Left = 0 (图片在左边,从左向右移动)
改成DetaX= -100
Image1.Left = 13300 '
(图片位置弄到右边,从右向左移动)
最后一段的
If Image1.Left > Me.Midth Then '
Image1.left = 0
是使移到右边的图片碰到右端后马上回到左端!重复移动!!!现在我改了移动方向和位置后!!这句就不对了!!!
希望高手帮我改这句!!使得图片向左边移动完后立刻回到右端重复刚才的移动!!!
急用啊!!这个周末前不交上就没成绩了!!!!! 展开
就是这样。。!!!高手指教!
Dim IsPlaying As Boolean '
Dim DetaX As Long '
Private Sub Form_Load()
Form1.BackColor = RGV(*******) '
IsPlaying = False '
DetaX= -100
Image1.Left = 13300 '
end Sub
(下来一段是启动的描述)
再下来
Private Sub Timer1_Timer()
Image1.Move Image1.Left + DetaX
(注意:)If Image1.Left > Me.Midth Then '
Image1.left = 0
End If
End Sub
我是就DetaX= 100
Image1.Left = 0 (图片在左边,从左向右移动)
改成DetaX= -100
Image1.Left = 13300 '
(图片位置弄到右边,从右向左移动)
最后一段的
If Image1.Left > Me.Midth Then '
Image1.left = 0
是使移到右边的图片碰到右端后马上回到左端!重复移动!!!现在我改了移动方向和位置后!!这句就不对了!!!
希望高手帮我改这句!!使得图片向左边移动完后立刻回到右端重复刚才的移动!!!
急用啊!!这个周末前不交上就没成绩了!!!!! 展开
3个回答
展开全部
Dim
r,
l,
s
As
Boolean
Private
Sub
Form_Load()
s
=
True
l
=
False
r
=
False
End
Sub
Private
Sub
Timer1_Timer()
If
Image1.Left
<=
0
Or
r
=
True
Then
Image1.Left
=
Image1.Left
+
100
l
=
False
r
=
True
End
If
If
Form1.Width
-
Image1.Width
<=
Image1.Left
Or
l
=
True
Then
Image1.Left
=
Image1.Left
-
100
r
=
False
l
=
True
End
If
If
(Image1.Left
<>
0
Or
Form1.Width
-
Image1.Width
<=
Image1.Left)
And
s
=
True
Then
Image1.Left
=
Image1.Left
+
100
l
=
False
r
=
True
s
=
False
End
If
End
Sub
我调试过可达到你的要求
我在窗口上添加了image控件
和timer控件
timer1.interval=1
image1.stretch=true
r,
l,
s
As
Boolean
Private
Sub
Form_Load()
s
=
True
l
=
False
r
=
False
End
Sub
Private
Sub
Timer1_Timer()
If
Image1.Left
<=
0
Or
r
=
True
Then
Image1.Left
=
Image1.Left
+
100
l
=
False
r
=
True
End
If
If
Form1.Width
-
Image1.Width
<=
Image1.Left
Or
l
=
True
Then
Image1.Left
=
Image1.Left
-
100
r
=
False
l
=
True
End
If
If
(Image1.Left
<>
0
Or
Form1.Width
-
Image1.Width
<=
Image1.Left)
And
s
=
True
Then
Image1.Left
=
Image1.Left
+
100
l
=
False
r
=
True
s
=
False
End
If
End
Sub
我调试过可达到你的要求
我在窗口上添加了image控件
和timer控件
timer1.interval=1
image1.stretch=true
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim r, l, s As Boolean
Private Sub Form_Load()
s = True
l = False
r = False
End Sub
Private Sub Timer1_Timer()
If Image1.Left <= 0 Or r = True Then
Image1.Left = Image1.Left + 100
l = False
r = True
End If
If Form1.Width - Image1.Width <= Image1.Left Or l = True Then
Image1.Left = Image1.Left - 100
r = False
l = True
End If
If (Image1.Left <> 0 Or Form1.Width - Image1.Width <= Image1.Left) And s = True Then
Image1.Left = Image1.Left + 100
l = False
r = True
s = False
End If
End Sub
我调试过可达到你的要求
我在窗口上添加了image控件 和timer控件 timer1.interval=1 image1.stretch=true
Private Sub Form_Load()
s = True
l = False
r = False
End Sub
Private Sub Timer1_Timer()
If Image1.Left <= 0 Or r = True Then
Image1.Left = Image1.Left + 100
l = False
r = True
End If
If Form1.Width - Image1.Width <= Image1.Left Or l = True Then
Image1.Left = Image1.Left - 100
r = False
l = True
End If
If (Image1.Left <> 0 Or Form1.Width - Image1.Width <= Image1.Left) And s = True Then
Image1.Left = Image1.Left + 100
l = False
r = True
s = False
End If
End Sub
我调试过可达到你的要求
我在窗口上添加了image控件 和timer控件 timer1.interval=1 image1.stretch=true
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Load()
Picture1.Left = Form1.Width - Picture1.Width
Timer1.Interval = 50
End Sub
Private Sub Timer1_Timer()
Picture1.Left = Picture1.Left - 100
If Picture1.Left < 0 Then
Picture1.Left = Form1.Width - Picture1.Width
End If
End Sub
还以为要左右晃呢,这次方向就对了
Picture1.Left = Form1.Width - Picture1.Width
Timer1.Interval = 50
End Sub
Private Sub Timer1_Timer()
Picture1.Left = Picture1.Left - 100
If Picture1.Left < 0 Then
Picture1.Left = Form1.Width - Picture1.Width
End If
End Sub
还以为要左右晃呢,这次方向就对了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询