用VB编程小球左右移动

我只知道向右移动
2025-06-27 13:19:51
推荐回答(1个)
回答1:

Dim fh As Integer
Private Sub Command1_Click()
Timer1.Enabled = True
fh = 1
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Shape1.Shape = 3
Timer1.Interval = 100
Timer1.Enabled = False
Command1.Caption = "开始"
Command2.Caption = "停止"
End Sub
Private Sub Timer1_Timer()
Shape1.Left = Shape1.Left + fh * 200
If Shape1.Left < 0 Then
Shape1.Left = 0
fh = -fh
End If
If Shape1.Left + Shape1.Width > Me.Width Then
Shape1.Left = Me.Width - Shape1.Width
fh = -fh
End If