我们课后的一个作业题
Dim hight As Integer, left1 As Integer
Dim bx As Integer, by As Integer
Private Sub Command1_Click()
hight = Shape1.Top
left1 = Shape1.Left
bx = 100
by = -100
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Command3_Click()
Shape1.Left = left1
Shape1.Top = hight
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Form1.Scale (0, 0)-(Picture1.ScaleWidth, Picture1.ScaleHeight)
End Sub
Private Sub Picture1_Click()
End Sub
Private Sub Timer1_Timer()
Shape1.Left = Shape1.Left + bx '小球向右运动
Shape1.Top = Shape1.Top + by '小球向顶端运动
End Sub
Private Sub Timer2_Timer()
Dim a As Integer
a = Int((Rnd * 2) + 1)
If Shape1.Left >= Picture1.ScaleWidth - Shape1.Width Then '判断小球是否到达最右端或是最顶端
If a = 1 Then
bx = -100
by = 100
Else
bx = -100
by = -100
End If
End If
If Shape1.Left <= 0 Then '判断小球是否到达最左端
If a = 1 Then
bx = 100
by = 100
Else
bx = 100
by = -100
End If
End If
If Shape1.Top <= 0 Then '判断小球是否到达最顶端
If a = 1 Then
bx = 100
by = 100
Else
bx = -100
by = 100
End If
End If
If Shape1.Top >= Picture1.ScaleHeight - Shape1.Height Then '判断小球是否到达最底端
If a = 1 Then
bx = 100
by = -100
Else
bx = -100
by = -100
End If
End If
End Sub
Dim hight As Integer, left1 As Integer
Dim bx As Integer, by As Integer
Private Sub Command1_Click()
hight = Shape1.Top
left1 = Shape1.Left
bx = 100
by = -100
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Command3_Click()
Shape1.Left = left1
Shape1.Top = hight
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Form1.Scale (0, 0)-(Picture1.ScaleWidth, Picture1.ScaleHeight)
End Sub
Private Sub Picture1_Click()
End Sub
Private Sub Timer1_Timer()
Shape1.Left = Shape1.Left + bx '小球向右运动
Shape1.Top = Shape1.Top + by '小球向顶端运动
End Sub
Private Sub Timer2_Timer()
Dim a As Integer
a = Int((Rnd * 2) + 1)
If Shape1.Left >= Picture1.ScaleWidth - Shape1.Width Then '判断小球是否到达最右端或是最顶端
If a = 1 Then
bx = -100
by = 100
Else
bx = -100
by = -100
End If
End If
If Shape1.Left <= 0 Then '判断小球是否到达最左端
If a = 1 Then
bx = 100
by = 100
Else
bx = 100
by = -100
End If
End If
If Shape1.Top <= 0 Then '判断小球是否到达最顶端
If a = 1 Then
bx = 100
by = 100
Else
bx = -100
by = 100
End If
End If
If Shape1.Top >= Picture1.ScaleHeight - Shape1.Height Then '判断小球是否到达最底端
If a = 1 Then
bx = 100
by = -100
Else
bx = -100
by = -100
End If
End If
End Sub


