我想实现两个图片的交替显示,同时两个图片是在随timer控件移动的。自己写了下面的程序,但是有问题。我刚学的vb所以可能程序里面有很多不完善的地方,也请高手帮忙晚上一下。eg.图片到form左右两端自动回头等。如果下面的程序错误严重,请重新写!!!Private Sub form_load()
Picture1.Visible = True
Picture2.Visible = True
Timer1.Interval = 50
Timer2.Interval = 50
Timer2.Enabled = False
End Sub
Private Sub timer1_timer()
Picture1.Left = Picture1.Left + 50
Picture2.Visible = False
Timer1.Enabled = False
Timer2.Enabled = True
Timer2.Interval = 50
End Sub
Private Sub timer2_timer()
Picture2.Left = Picture2.Left + 50
Picture1.Visible = False
Timer2.Enabled = False
Timer1.Enabled = True
Timer1.Interval = 50
End Sub
Picture1.Visible = True
Picture2.Visible = True
Timer1.Interval = 50
Timer2.Interval = 50
Timer2.Enabled = False
End Sub
Private Sub timer1_timer()
Picture1.Left = Picture1.Left + 50
Picture2.Visible = False
Timer1.Enabled = False
Timer2.Enabled = True
Timer2.Interval = 50
End Sub
Private Sub timer2_timer()
Picture2.Left = Picture2.Left + 50
Picture1.Visible = False
Timer2.Enabled = False
Timer1.Enabled = True
Timer1.Interval = 50
End Sub
Private Sub form_load()
Picture1.Visible = True
Picture2.Visible = True
Timer1.Interval = 50
Timer2.Interval = 50
Timer2.Enabled = False
End Sub
Private Sub timer1_timer()
Timer1.Enabled = False
Picture1.Visible = True
Picture1.Left = Picture1.Left + 50
Picture2.Visible = False
Timer2.Enabled = True
End Sub
Private Sub timer2_timer()
Timer2.Enabled = False
Picture2.Visible = True
Picture2.Left = Picture2.Left + 50
Picture1.Visible = False
Timer1.Enabled = True
End Sub
Picture1.Visible = True
Picture2.Visible = False
Picture1.Tag = 1
Picture2.Tag = 1
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub timer1_timer()
Static i As Integer
i = i + 1
If i Mod 2 = 1 Then
If (Picture1.Left + Val(Picture1.Tag) * 500) > (Me.Width - Picture1.Width) Then
Picture1.Tag = -1
Picture1.Left = Me.Width - Picture1.Width
ElseIf (Picture1.Left + Val(Picture1.Tag) * 500) < 0 Then
Picture1.Tag = 1
Picture1.Left = 0
Else
Picture1.Left = Picture1.Left + Val(Picture1.Tag) * 500
End If
Picture1.Visible = True
Picture2.Visible = False
Else
If (Picture2.Left + Val(Picture2.Tag) * 500) > (Me.Width - Picture2.Width) Then
Picture2.Tag = -1
Picture2.Left = Me.Width - Picture2.Width
ElseIf (Picture2.Left + Val(Picture2.Tag) * 500) < 0 Then
Picture2.Tag = 1
Picture2.Left = 0
Else
Picture2.Left = Picture2.Left + Val(Picture2.Tag) * 500
End If
Picture2.Visible = True
Picture1.Visible = False
End If
End Sub