📄 控件-定时器.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>控件-定时器</title>
</head>
<body bgcolor="#CCFFFF" vlink="#0000FF">
<p align="center" style="margin-top: 0; margin-bottom: 0"><font color="#FF0000"><font face="华文彩云" size="6">VB程序设计基础</font></font></p>
<p align="left" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><br>
<font color="#0000FF">九、定时器</font><br>
<font color="#0000FF">定时器</font>Timer 可以控制代码<font color="#800000">定时</font>运行,就像<font color="#800000">屏幕</font>保护程序一样,代码是Timer_Timer()<br>
<font color="#0000FF">启动</font>VB,修改好窗体的标题<font color="#800000">Caption</font>、颜色和图标Icon属性,再添加一个<font color="#800000">标签</font>Label1,修改它的Caption属性为<font color="#800000">空</font>,再修改它的颜色,字体等属性,以“<font color="#800000">定时器</font>”(或MyTimer)为文件名<font color="#800000">保存文件到自己的文件夹。</font><br>
<font color="#0000FF">在</font>工具箱中选中定时器,一个<font color="#800000">小闹钟</font>的图标,在窗体绘制一个定时器,在属性窗口中找到<font color="#800000">Interval</font>输入2000,这个属性是设置时间的,单位是<font color="#800000">毫秒</font>,1000毫秒等于1秒。<font color="#800000">保存一下</font>程序<br>
<font color="#0000FF">启动</font>程序,看看定时器在哪儿,好像找不着,没看到小闹钟,这是因为定时器是在<font color="#800000">代码</font>中设置的。<br>
<font color="#0000FF">关闭</font>程序回到窗体中,<font color="#800000">双击</font>定时器对象进入<font color="#800000">代码</font>窗口。<br>
<font color="#0000FF">按一下</font>Tab键缩进准备输入<font color="#800000">代码</font>,我们要让标签过两秒就<font color="#800000">显示</font>一段文字,代码为:<br>
Static i as boolean <font color="#008000">'定义一个布尔型变量i,布尔型变量只有真假(True 或Flase)</font><br>
if i = false then<br>
label1.caption="保护视力"<br>
else<font color="#008000"> '否则 i =True</font><br>
label1.caption="预防近视"<br>
end if<font color="#008000"> '显示两句话</font><br>
i = Not i <font color="#008000">'换一个布尔值</font><br>
<font color="#0000FF">检查</font>一下代码的<font color="#800000">中英文</font>,理解一下代码的含义,<font color="#800000">保存一下</font>程序<br>
<font color="#0000FF">单击</font>启动按钮,等待两秒你看到了什么呢?<br>
<font color="#0000FF">回到</font>代码窗口,我们来<font color="#800000">理解</font>一下代码的意义,因为<font color="#800000">只显示</font>两句,所以不是这句就是那句,当然显示哪一句,要看看变量<font color="#800000">i</font>的值,i
为真(<font color="#800000">True</font>)时显示“预防近视”,<font color="#800000">否则</font>就显示“保护视力”,这次
i 为真,Not以后<font color="#800000">下次</font>就变成假,Not 是否定的意思。<br>
<font color="#0000FF">你</font>注意到了没有?Windows在提示时常常会<font color="#800000">响</font>一声,这句代码是<font color="#800000">Beep</font> 我们把这一句加到Else句上面的一个空行,注意VB中每一行<font color="#800000">只写一句</font>,代码变<font color="#800000">红</font>了就是错了。<font color="#800000">完整</font>的代码是:<br>
Static i As Boolean <font color="#008000">'定义一个布尔型变量
i ,布尔型变量只有真假(True 或Flase)</font><br>
If i = False Then<br>
Label1.Caption = "保护视力"<br>
Beep <font color="#008000">'响铃</font><br>
Else<font color="#008000"> '否则i=True</font><br>
Label1.Caption = "预防近视"<br>
End If <font color="#008000"> '显示两句话</font><br>
i = Not i <font color="#008000"> '换一个布尔值</font></p>
<p align="left" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font color="#0000FF">本节</font>学习了定时器的使用和设置代码<br>
<a href="心灵窗口.exe">心灵窗口</a> <font size="2">(在弹出的对话框中选择“<font color="#800000">在当前位置运行该程序</font>”和“<font color="#800000">是</font>”)</font></p>
<font SIZE="1" COLOR="#000000">
<p style="line-height: 200%; margin-top: 2; margin-bottom: 0">本教程由86团学校TeliuTe制作|著作权所有,不得用于商业用途</p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">美丽的校园……</p>
</font>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -