【正确答案】[解析] 控件已经建立完好,只需设计事件过程即可。
Timer1控件的Interval属性是用来控制计时器事件发生的时间间隔,通过题意可知该属性设置为100(Interval是以毫秒为单位)。当单击“发射”按钮时开始计时,把计时器控件的Enabled属性设置为True。如果使航天器即P1停止移动,需要将计时器控件的Enagled属性设置为False。解题步骤:
第一步:建立界面并设置控件属性。程序用到的控件及其属性见表20-3。
表 20-3
控 件 | 属 性 | 设 置 值 |
| 命令按钮 | Name Cption | C1 发射 |
| 图片框 | Name Picture | p2
|
| 图片框 | Name Picture | P1 |
| 计时器 | Name Interval | Timer1 100 |
第二步:编写程序代码。
程序提供的代码:
Private Sub C1_Click()
' Timer1.Enabled=
End Sub
Private Sub Timer1_Timer()
Static a%
a=a+1
' If P1.Top>P2.Top+P2.? Then
P1.Move P1.Left, P1.Top-5-a, P1.Width, P1.Height
Else
' Timer1.?=False
End If
End Sub
参考代码:
Private Sub C1_Click()
Timer1.Enabled=True
End Sub
Private Sub Timer1_Timer()
Static a%
a=a+1
If P1.Top>P2.Top+P2.Height Then
P1.Move P1.Left, P1.Top-5-a, P1.Width, P1.Height
Else
Timer1.Enabled=False
End If
End Sub
第三步:调试并运行程序。
第四步:按题目要求存盘。
(2) [解析] 在窗体上建立好控件后,先设置控件属性,再编写事件过程。
在文本框里显示的内容通过文本框的Text属性设置。Value属性用来表示复选框后单选框的状态。对于单选框来说,Value属性可设置为True或False当设置为True时,该单选按钮是被选中的,否则该单选按钮没有被选中。对于复选框来说,Value属性可以设置为0、1或2。其中:0—表示没有选中该复选框;1—表示选中该复选框;2—表示该复选框被禁止(灰色)。解题步骤:
第一步:建立界面并设置控件属性。程序中用到的控件及其属性见表20-4。
表 20-4
对 象 | 属 性 | 设 置 值 |
| 复选按钮 | Name Cption | Ch1 体育 |
| 复选按钮 | Name Cption | Ch2 音乐 |
| 单选按钮 | Name Cption | Op1 男生 |
| 单选按钮 | Name Cption | Op1 女生 |
| 文本框 | Name | Text1 |
| 文本框 | Name | Text2 |
| 命令按钮 | Name Cption | C1 确定 |
第二步:编写程序代码。
参考代码:
程序提供的代码:
Private Sub Form_Unload(Cancel As Integer)
Open "out4.txt" For Output As #1
Print #1, Op1.Value, Op2.Value, Text1.Text
Print #1, Ch1.Value, Ch2.Value, Text2.Text
Close #1
End Sub
参考代码:
Private Sub C1_Click()
If Op1.Value Then
Text1.Text="我是" & Op1.Caption
Else
Text1.Text="我市" & Op2.Caption
End If
Text2.Text="我的爱好是"
If Ch1.Value=1 Then
Text2.Text=Text2.Text & Ch1.Caption
End If
If Ch2.Value=1 Then
Text2.Text=Text2.Text & Ch2.Caption
End If
End Sub
Private Sub Form Unload(Cancel As Integer)
Open "out4.txt" For Output As #1
Print #1, Op1.Value, Op2.Value, Text1.Text
Print #1, Ch1.Value, Ch2.Value, Text2.Text
Close #1
End Sub
第三步:调试并运行程序。
第四步:按题目要求存盘。