⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 控件-复选框.htm

📁 几种VB程序和案例
💻 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>
&nbsp;&nbsp;&nbsp; <font color="#0000FF">复选框</font>CheckBox 
是用来标记是否<font color="#800000">选中</font>的控件,代码是Check1.Value=(0,1)  
也就是或者选中,或者没有选中。<br> 
&nbsp;&nbsp;&nbsp; <font color="#0000FF">启动</font>VB、设置好窗体的标题Caption为“<font color="#800000">复选框</font>”以及背景色、图标,添加一个标签Label,Caption改为“<font color="#800000">我的复选框</font>”,以“<font color="#800000">复选框</font>”(或MyCheckBox)为文件名,<font color="#800000">保存文件到自己的文件夹中</font>。<br>
&nbsp;&nbsp;&nbsp;<font color="#0000FF"> 找到</font>工具箱中的一个<font color="#800000">打勾的</font>控件,这就是复选框,添加一个到窗体中,在属性窗口中修改它的Caption为“<font color="#800000">复选框的值</font>”,再修改字体、字号,把提示<font color="#800000">ToolTipText</font>设为“这是第一个复选框”。<br>
&nbsp;&nbsp;&nbsp; <font color="#0000FF">单击</font>“启动”按钮,运行一下程序,在复选框上<font color="#800000">单击</font>一下鼠标,可以看到在方框中打了一个勾,表示选中了,再单击一下,勾又去掉了,这样就可以来回选择。<br>
&nbsp;&nbsp;&nbsp; <font color="#0000FF">退出</font>程序回到窗口中,再添加一个文本框,修改一下它的<font color="#800000">Text</font>属性为“文本框”,ToolTipText为“这儿要显示代码”,字体调大一些<font color="#800000">四号</font>左右。<br>
&nbsp;&nbsp;&nbsp; <font color="#0000FF">双击</font>复选框进入代码窗口,我们来设置代码,按一下<font color="#800000">Tab键</font>缩进,添加代码:&nbsp; 
<font color="#800000">Text1.text=Check1.value</font> 注意使用VB的自动完成功能。这一句代码让文本框里显示复选框Value值,当然是在单击复选框时(第一行Check1_Click())<br> 
&nbsp;&nbsp;&nbsp; <font color="#0000FF">运行</font>程序,单击复选框,看一下文本框中的值,<font color="#800000">打勾时</font>值是1还是0  
?<br> 
&nbsp;&nbsp;&nbsp; <font color="#0000FF">退出</font>程序回到窗口,接着添加代码,我们用复选框来设置文本框的<font color="#800000">字体</font>。<br>
&nbsp;&nbsp;&nbsp; <font color="#0000FF">再</font>添加两个复选框,一个Caption是“<font color="#800000">黑体</font>”,提示为“这是<font color="#800000">第二个</font>复选框”另一个是“<font color="#800000">隶书</font>”,提示为“这是第三个复选框”。<br>
&nbsp;&nbsp;&nbsp; <font color="#0000FF">在</font>“黑体”复选框上<font color="#800000">双击鼠标</font>左键,进入代码窗口,按一下Tab键缩进,输入:<br>
<font color="#800000">
if check2.value =1 then</font> 按一下回车键进入下一行,再按一下<font color="#800000">Tab键</font>缩进,输入:<br>
<font color="#800000">
Text1.font=&quot;黑体&quot;</font> 
注意中英文切换。再按一下回车键进入下一行,按一下退格键,删除缩进输入<font color="#0000FF"> 
</font><font color="#800000">end if</font><br> 
&nbsp;&nbsp;&nbsp; <font color="#0000FF">整个</font>代码是:<br>
if check2.value=1 then<br> 
&nbsp;&nbsp;&nbsp; Text1.font=&quot;黑体&quot;<br>
end if<br> 
&nbsp;&nbsp;&nbsp; <font color="#0000FF">同样</font>双击“<font color="#800000">隶书</font>”复选框,进入代码窗口,照着<font color="#800000">上面的</font>例子输入:<br>
if check3.value=1 then<br> 
&nbsp;&nbsp;&nbsp; text1.font=&quot;隶书&quot;<br>
end if<br> 
&nbsp;&nbsp;&nbsp;<font color="#0000FF"> 检查</font>一下三行代码的正确性,<font color="#800000">保存一下文件</font><br>
&nbsp;&nbsp;&nbsp; <font color="#0000FF">单击</font>“启动”按钮运行程序,在<font color="#800000">文本框</font>中输入自己的<font color="#800000">姓名</font>,然后单击两个复选框看一下变化。<br>
&nbsp;&nbsp;&nbsp; <font color="#0000FF">关闭</font>程序回到代码窗口,我们来<font color="#800000">分析</font>一下代码,第一行if  
check2.value=1 then 是一个<font color="#800000">假设</font>语句,if 
是如果的意思,也就是<font color="#800000">如果check2.value=1</font> 表示复选框2<font color="#800000">打上勾</font>,那么 
(then是那么的意思),第二句<font color="#800000">text1.font=&quot;隶书&quot;</font> ,font是字体的单词,字体改为隶书,第三句 
<font color="#800000"> 
end if</font> 是结束if语句,end是结束的意思。<br> 
&nbsp;&nbsp;&nbsp; <font color="#0000FF">好</font>,再运行一下程序,点击字体的复选框,<font color="#800000">打勾</font>就改变字体,但是有一点、勾去掉了,字体却没有回去,我们的代码还不完善。<br>
&nbsp;&nbsp;&nbsp; <font color="#0000FF">关闭</font>程序回到代码窗口,找到Private Sub 
<font color="#800000">Check2_Click</font>()这一段代码过程,刚才我们在if语句中假设打勾,如果不打,就叫“否则的话”代码是 
<font color="#800000"> 
Else&nbsp;</font><br>
&nbsp;&nbsp;&nbsp; <font color="#0000FF">找到</font>if语句的<font color="#800000">第二行</font>,也就是Text1.font=&quot;黑体&quot;这一句,把光标移到它的最后面按一下回车键,插入一个空行,按一下<font color="#800000">退格键</font>删除缩进,输入 
<font color="#800000"> 
else</font> 再按一下<font color="#800000">回车键</font>插入一个空行,按一下Tab键缩进,输入:<br>
if check3.value=1 then<br> 
&nbsp;&nbsp;&nbsp; text1.font=&quot;隶书&quot;<br>
else<br>
&nbsp;&nbsp;&nbsp; text1.font=&quot;宋体&quot;<br>
end if<br> 
&nbsp;&nbsp;&nbsp; <font color="#0000FF">这几行</font>代码的意思,是看看check3有没有选中,<font color="#800000">如果选中</font>就用check3的字体“隶书”,<font color="#800000">否则</font>就用默认的“宋体”。<font color="#800000">保存一下程序</font><br>
&nbsp;&nbsp;&nbsp; <font color="#0000FF">运行</font>一下程序,选中两个复选框,再去掉“黑体”的勾,看一下变化。<br>
&nbsp;&nbsp;&nbsp; <font color="#0000FF">关闭</font>程序回到代码窗口,同样找到Private Sub 
<font color="#800000">Check3</font>_Click()代码过程,按照上面的例子把光标移到<font color="#800000">Text.Font=&quot;隶书&quot;</font>这一句的最后按一下<font color="#800000">回车键</font>插入空行,按退格键删除缩进,输入 
<font color="#800000"> 
else </font>再按回车键插入<font color="#800000">空行</font>,按Tab键缩进,加入:<br>
if check2.value=1 then<br> 
&nbsp;&nbsp;&nbsp; text1.font=&quot;黑体&quot;<br>
else<br>
&nbsp;&nbsp;&nbsp; text1.font=&quot;宋体&quot;<br>
end if<br> 
&nbsp;&nbsp;&nbsp; <font color="#0000FF">输完后</font>一定要<font color="#800000">检查</font>一遍有没有漏掉<font color="#800000">缩进</font>,中<font color="#800000">英</font>文错误和错句、漏句。<font color="#800000">保存一下程序</font>,整个的代码是:<br>
Private Sub Check2_Click()<br> 
&nbsp;&nbsp;&nbsp; If Check2.Value = 1 Then<br> 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Text1.Font = &quot;黑体&quot;<br> 
&nbsp;&nbsp;&nbsp; Else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; If Check3.Value = 1 Then<br> 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Text1.Font = &quot;隶书&quot;<br> 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Else<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Text1.Font = &quot;宋体&quot;<br> 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; End If<br> 
&nbsp;&nbsp;&nbsp; End If<br> 
End Sub<br> 
<br> 
Private Sub Check3_Click()<br> 
&nbsp;&nbsp;&nbsp; If Check3.Value = 1 Then<br> 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Text1.Font = &quot;隶书&quot;<br> 
&nbsp;&nbsp;&nbsp; Else<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; If Check2.Value = 1 Then<br> 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Text1.Font = &quot;黑体&quot;<br> 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Else<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Text1.Font = &quot;宋体&quot;<br> 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; End If<br> 
&nbsp;&nbsp;&nbsp; End If<br> 
End Sub<br> 
<br> 
&nbsp;&nbsp;&nbsp; <font color="#0000FF">运行</font>程序,看一下我们的代码所起的作用,程序也变得越来越有意思了。<br>
&nbsp;&nbsp;&nbsp; <font color="#0000FF">本节</font>学习了复选框和if语句的用法。<br>
&nbsp;&nbsp;&nbsp; <a href="变体文字.exe">变体文字</a> <font size="2">(在弹出的对话框中选择“<font color="#800000">在当前位置运行该程序</font>”和“<font color="#800000">是</font>”)</font></p>     
                   
                    
<p align="left" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>     
                   
                    
<font SIZE="1" COLOR="#000000">    
<p style="line-height: 100%; margin-top: 0; 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 + -