在窗体内加入控件Picture1,Timer1(internal=100),然后复制下面代码,运行即可:Option ExplicitPublic i As Integer, x As Integer, y As IntegerDim Shape1 As ObjectPrivate Sub Form_Load()
x = 10
y = 10
'设置小球移动幅度为10
Timer1.Interval = 10
'移动时间间距为10
Set Shape1 = Me.Controls.Add("VB.shape", "shape1", Picture1)
Shape1.Left = 0
Shape1.Top = 0
Shape1.Width = 615
Shape1.Height = 615
Shape1.Visible = TrueEnd SubPrivate Sub Timer1_Timer()
Shape1.Left = Shape1.Left + x
Shape1.Top = Shape1.Top + y
If Shape1.Left + Shape1.Width > Picture1.Width Or Shape1.LeftPicture1.Height Or Shape1.Top < 0 Then y = -y
'这两行是指如果小球碰到边框了,自动弹回来End Sub
|