目的是要让他运行后 蓝色小球在白框内做直线运动碰撞,弹回后继续运动
3个单选框控制速度
做了一上午都没法让它动起来唉
大家帮帮忙啊现在把Option1(0).Value = True 改为Option1.Value = True
Private Sub option1_click(index As Integer)改为Private Sub option1_click()
可以勉强进入界面但看不到预期效果
以下代码中的乱码都是一些汉字
==============================
Private Sub Cmdstart_Click()
If cmdstart.Caption = "¿ªÊ¼" Then
cmdstart.Caption = "ÔÝÍ£"
'randomize
intmotion = (Int(Rnd * 10) Mod 4) + 1
tmrcount.Interval = 10
tmrcount.Enabled = True
Else
tmrcount.Interval = 0
cmdstart.Caption = "¿ªÊ¼"
tmrcount.Enabled = False
End If
End Sub
Private Sub form1_load()
intmotion = 1
intspeed = 10
Option1(0).Value = True
End Sub
Private Sub option1_click(index As Integer)
Select Case index
Case 0
intspeed = 10
Case 1
intspeed = 15
Case 2
intspeed = 20
End Select
End Sub
Private Sub tmrcount_timer()
Select Case intmotion
Case 1
imgball.Move imgball.Left - intspeed, imgball.Top - intspeed '×óÉÏ
If imgball.Top <= 0 Then
intmotion = 3
ElseIf imgball.Left <= 0 Then
intmotion = 4
End If
Case 2
imgball.Move imgball.Left + intspeed, imgball.Top - intspeed 'ÓÒÉÏ
If imgball.Left >= Picture1.Width - imgball.Width Then
intmotion = 1
ElseIf imgball.Top <= 0 Then
intmotion = 3
End If
Case 3
imgball.Move imgball.Left + intspeed, imgball.Top + intspeed 'ÓÒÏÂ
If imgball.Left >= Picture1.Width - imgball.Width Then
intmotion = 4
ElseIf imgball.Top >= Picture1.Height - imgball.Height Then
intmotion = 2
End If
Case 4
imgball.Move imgball.Left - intspeed, imgball.Top - intspeed 'ÓÒÏÂ
If imgball.Left <= 0 Then
intmotion = 3
ElseIf imgball.Top >= Picture1.Height - imgball.Height Then
intmotion = 1
End If
End Select
End Sub
3个单选框控制速度
做了一上午都没法让它动起来唉
大家帮帮忙啊现在把Option1(0).Value = True 改为Option1.Value = True
Private Sub option1_click(index As Integer)改为Private Sub option1_click()
可以勉强进入界面但看不到预期效果
以下代码中的乱码都是一些汉字
==============================
Private Sub Cmdstart_Click()
If cmdstart.Caption = "¿ªÊ¼" Then
cmdstart.Caption = "ÔÝÍ£"
'randomize
intmotion = (Int(Rnd * 10) Mod 4) + 1
tmrcount.Interval = 10
tmrcount.Enabled = True
Else
tmrcount.Interval = 0
cmdstart.Caption = "¿ªÊ¼"
tmrcount.Enabled = False
End If
End Sub
Private Sub form1_load()
intmotion = 1
intspeed = 10
Option1(0).Value = True
End Sub
Private Sub option1_click(index As Integer)
Select Case index
Case 0
intspeed = 10
Case 1
intspeed = 15
Case 2
intspeed = 20
End Select
End Sub
Private Sub tmrcount_timer()
Select Case intmotion
Case 1
imgball.Move imgball.Left - intspeed, imgball.Top - intspeed '×óÉÏ
If imgball.Top <= 0 Then
intmotion = 3
ElseIf imgball.Left <= 0 Then
intmotion = 4
End If
Case 2
imgball.Move imgball.Left + intspeed, imgball.Top - intspeed 'ÓÒÉÏ
If imgball.Left >= Picture1.Width - imgball.Width Then
intmotion = 1
ElseIf imgball.Top <= 0 Then
intmotion = 3
End If
Case 3
imgball.Move imgball.Left + intspeed, imgball.Top + intspeed 'ÓÒÏÂ
If imgball.Left >= Picture1.Width - imgball.Width Then
intmotion = 4
ElseIf imgball.Top >= Picture1.Height - imgball.Height Then
intmotion = 2
End If
Case 4
imgball.Move imgball.Left - intspeed, imgball.Top - intspeed 'ÓÒÏÂ
If imgball.Left <= 0 Then
intmotion = 3
ElseIf imgball.Top >= Picture1.Height - imgball.Height Then
intmotion = 1
End If
End Select
End Sub
1 在 Picture1 中必须放名为 imgball 的 Image 控件。
2 放一个名为 cmdstart 的按钮,按了才会启动。
3 放一个 Option 数组(将你的 Option 复制粘贴 2 次)。
4 放一个名为 tmrcount 的 Timer 控件。