我是个Vb菜鸟。现在要用shape控件(我已经画好了圆和四条线)做了一个小球碰壁弹回的程序,要用timer来做。好像是不能超过什么line1。left之类的
用if then 语句
关于Vb弹小球的问题(如果满意追加)
答案:1 悬赏:0 手机版
解决时间 2021-02-27 18:53
- 提问者网友:火车头
- 2021-02-27 13:25
最佳答案
- 五星知识达人网友:一秋
- 2021-02-27 14:23
Dim hb As Single, lb As Single
Private Sub Command1_Click()
hb = InputBox("行变速度")
lb = InputBox("列变速度")
Me.Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
zb = Me.Shape1.Left: kuan = Me.Shape1.Width: gao = Me.Shape1.Height
ding = Me.Shape1.Top
If zb + kuan + hb > Me.Line3.X1 Then
hb = -hb
End If
If zb + hb < Me.Line1.X1 Then
hb = -hb
End If
If ding + gao + lb > Me.Line2.Y1 Then
lb = -lb
End If
If ding + lb < Me.Line4.Y1 Then
lb = -lb
End If
Me.Shape1.Left = zb + hb
Me.Shape1.Top = ding + lb
'Debug.Print hb, lb
End Sub
Private Sub Command1_Click()
hb = InputBox("行变速度")
lb = InputBox("列变速度")
Me.Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
zb = Me.Shape1.Left: kuan = Me.Shape1.Width: gao = Me.Shape1.Height
ding = Me.Shape1.Top
If zb + kuan + hb > Me.Line3.X1 Then
hb = -hb
End If
If zb + hb < Me.Line1.X1 Then
hb = -hb
End If
If ding + gao + lb > Me.Line2.Y1 Then
lb = -lb
End If
If ding + lb < Me.Line4.Y1 Then
lb = -lb
End If
Me.Shape1.Left = zb + hb
Me.Shape1.Top = ding + lb
'Debug.Print hb, lb
End Sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯