一个简单的VB编程 会的帮忙

来源:百度知道 编辑:UC知道 时间:2024/05/31 08:39:57
制作一个水平来回移动两个小图标的程序。一个图标从左向右移动,另一个则从右向左移动,不断进行,直到单击窗体后才停止在初始位置

我用两个label来代表小图标,需要一个timer控件和两个label控件:
Option Explicit
Dim L1, L2 As Integer
Dim isStop As Boolean

Private Sub Form_Click()
If isStop = True Then
isStop = False
Else
isStop = True
End If
End Sub

Private Sub Form_Load()
Timer1.Interval = 200
L1 = Label1.Left
L2 = Label2.Left
isStop = False
End Sub

Private Sub Timer1_Timer()
If isStop = True And Abs(Label1.Left - L1) < 50 Then
Label1.Left = L1
Else
If Label1.Left > Me.Width Then Label1.Left = -Label1.Width
Label1.Left = Label1.Left + 50

End If
If isStop = True And Abs(Label2.Left - L2) < 50 Then
Label2.Left = L2
Else
If Label2.Left < -Label2.Width Then Label2.Left = Me.Width
Label2.Left = Label2.Left - 50

End If

End Sub