在VB中,可以通过以下3种方式实现简单的动画:
u 使用Move方法移动图片
例题3:任意移动命令按钮的位置。
Private Sub Command1_Click()
Print"你赢了!!!"
End Sub
Private Sub Command1_MouseMove()
X= Abs(Rnd(1)* Form1.Width - Command1.Width)
Y = Abs(Rnd(1)* Form1.Height - Command1.Height)
Command1.Move X, Y
End Sub
v 用不同的图形交替显示动画
例题4:在原地摆动翅膀的海鸥。
Private Sub Form_Load()
Image1.Visible= True
Image2.Visible = False
Image3.Visible = False
End Sub
Private Sub Timer1_Timer()
IfImage1.Visible Then
Image2.Visible= True
Image1.Visible= False
ElseIfImage2.Visible Then
Image3.Visible= True
Image2.Visible= False
ElseIfImage3.Visible Then
Image1.Visible= True
Image3.Visible= False
End If
End Sub
w 画一个擦一个,利用DrawMode=7
例题5:沿正弦曲线滚动的小球。
Private Sub Form_Paint()
Dimx As Integer
Dim y As Integer
DrawWidth= 10
FillStyle= 0
DrawMode= 7
For x = 50 To 8000
y = 1200 * Sin(x * 3.14 / 1800) + 1300
Circle (x, y), 50, vbCyan
Circle (x, y), 50, vbCyan
Next x
End Sub