Visual Basic和结构化程序相比,增加了对象的“方法”功能。充分掌握这 种不同于对象属性的“方法”,对可视化应用的开发极为重要。下面,以VB4.0的 move方法为例,说明该方法在动画中的应用。 本例欲通过move方法完成一只蝴蝶的飞翔过程。通过定时器的中断,每隔一 定时间(本例为0.2秒),在屏幕上移动蝴蝶的位置,并且改变蝴蝶的形态(展翅 和收翅),于是利用视觉的暂存效应,看到蝴蝶栩栩如生的飞行场面。蝴蝶的位置 的移动就由move方法来实现,move方法使用的格式如下: 对象. move left, top 其中left为对象左边界的水平坐标(x轴),top为对象上边界的垂直坐标 (Y轴),本例中的对象框(image box),名字为main。 蝴蝶的展翅和收翅图象由位图文件bfly1.bmp bfly2.bmp来提供,并可根据 需要制作其它飞行的位图文件,以使效果更加逼真。 本例中窗体结构和各个对象的属性设置如下: 对象 属性设置 窗体caption 蝴蝶飞行动画设计 图象框 name main picture bfly1 图象框 name openwings picture bfly1 图象框 name closewings picture bfly2 命令框 name command1 caption E&xit 定时器 name timer1 interval 200 有关程序比较简单,代码如下: 定时器中断程序: Private SubTimer-Timer() Static PickBmp As Integer Main.Move Main.Left +20,Main.Top -5 If PickBmp Then Main.Picture =Open Wings.Picture’Displays the open butterfly picture. Else Main.Picture =Close Wings.Picture’Displays the closed butterfly picture. End If PickBmp=Not PickBmp’Toggle the value. End Sub 退出按钮(exit)程序: Private Sub Command1-Click() Unload Me End End Sub 这样,利用VB的move方法和其它对象属性,就可以实现更加复杂的动画 设计。