【正确答案】① 对象主要属性设置如表4所示。
表 4
对象 | 对象名 | 属性名 | 属性值 |
窗体 | Form1 | Caption | Form1 |
图片框 | P1 | | |
图片框 | P2 | Picture | CARS.ICO |
命令按钮 | C1 | Caption | 开车 |
计时器 | Timer1 | Interval | 20 |
计时器 | Timer2 | Interval | 1000 |
| | Enabled | False |
② 分析:窗体上的两个图片框、两个计时器和一个命令按钮,它们的属性按表4的内容进行设置。对于一个含有计时器控件的窗体,当属性Enabled为 True时,每经过一段由属性Interval指定的时间(毫秒)间隔,就产生一个 Timer事件。当属性Enabled为False或属性Interval为O时,将终止Timer事件。在程序运行期间可以用Load-Picture函数把图形文件装入窗体、图片框或图像框中。
Move方法的格式为:Object. Move left, top, width, height
· object为一个对象;
· left(必需的)为object左边的水平坐标(x—轴);
· top(可选的)为object顶边的垂直坐标(y—轴);
· width(可选的)为object新的宽度;
· height(可选的)为object新的高度。
③ 编程代码:
Dim a%,b As Boolean
Private Sub C1_Click()
Timer2. Enabled=
True b=True
End Sub
Private Sub Timer1_Timer()
a=a+1
If a>6 Then
a=1
End If
Select Case a
Case 1
P1.Picture=LoadPicture("黄灯.ico")
Case 2,3
P1.Picture=LoadPicture("红灯.ico")
Case 4,5,6
P1.Picture=LoadPieture("
绿灯.ico")
If b Then Timer2. Enabled=True
End Select
End Sub
Private Sub Timer2_Timer()
If (a<4) And (P2. Left>P1.Left And P2.Left<P1.Left+P1. Width)
Or P2. Left<=100 Then
Timer2. Enabled=
False Else
P2. Move
P2. Left—10, P2. Top, P2.Width, P2.Height
End If
End Sub