示意图:
源码如下,请先试着自已编写,实在不行的话就花10块钱看看吧。。。
[UseMoney=10]
Option Explicit
Dim dx As Integer, dy As Integer '声明两个变量,dx为横向步进大小,dy为纵向步进大小
Private Sub Form_Load() '在Form_Load中初始化dx,dy两个变量 dx = 50 dy = 50 End Sub
Private Sub Form_Resize() '窗体大小发生变化后,将小球移到窗体中间 Shape1.Move Me.ScaleWidth / 2, Me.ScaleHeight / 2 End Sub
Private Sub Timer1_Timer() '控制小球运行,靠边时反疿 If Shape1.Left <= 0 Or Shape1.Left + Shape1.Width >= Me.ScaleWidth Then dx = -dx If Shape1.Top <= 0 Or Shape1.Top + Shape1.Height > Me.ScaleHeight Then dy = -dy Shape1.Move Shape1.Left + dx, Shape1.Top + dy End Sub
[/UseMoney]