📄 class_book_begin063.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
.redLink{ color:red;}
.blueLink{color:blue;}
A{font-size:12pt;text-decoration:none;}
P{font:12pt;line-height:22px;}
a:hover{text-decoration:underline}
h2{font-size:30px;text-align:center;color:rgb(0,144,144);letter-spacing:.5em;font-weight:bold}
.whiteB{color:black;background-color:white;}
.blueB{color:yellow;background-color:blue;}
.blackB{color:white;background-color:black;}
</style>
<title>第六章:输入(一)</title>
</head>
<script langue="javascript">
<!--
var source;
var flagDU="Up";
var oldClass="";
function ChangeColor(){
source=window.event.srcElement;
if (source.className=="redLink"){
source.className="blueLink";
}
else{
source.className="redLink";
}
}
function moveChangeBack(){
source=window.event.srcElement;
if (source.className==oldClass){oldClass=source.className;
if (flagDU=="Up"){
if (source.className="whiteB"){
source.className="blueB";
}else{
source.className="whiteB";
}
}else{source.className="blackB";
}
}else{//oldClass=source.className;
if (source.className=="whiteB"){
source.className="blueB";
}else{
source.className="whiteB";
}
}
}
function clickChangeBack(){
index01.className="whiteB"
index02.className="whiteB"
source=window.event.srcElement;
source.className="blackB";
flagDU="Down";
oldClass=source.className;
}
function returnValue(){
index01.className="whiteB";
index02.className="whiteB";
flagDU="Up";
}
function getAppVersion()
{
appname= navigator.appName;
appversion = navigator.appVersion;
majorver = appversion.substring(0, 1);
if ( (appname == "Netscape") && ( majorver >= 3 ) ) return 1;
if ( (appname == "Microsoft Internet Explorer") && (majorver>= 4) ) return 1;
return 0;
}
function switchGraphic(num, imgname) {
if (getAppVersion()) {
document[imgname].src = img[num].src;
}
}//-->
</script>
<body>
<script language="javascript">
<!--
imgsrc = new Array();
imgsrc[0] = "images/dot_blank.gif";
imgsrc[1] = "images/dot_filled.gif";
if (getAppVersion())
{
img = new Array();
for (i = 0; i < imgsrc.length; i++)
{
img[i] = new Image();
img[i].src = imgsrc[i];
}
}
//-->
</script>
<div align="center"><center>
<table border="0" cellpadding="8" cellspacing="0" width="100%">
<tr>
<td width="24%" valign="top"><h2><img src="../images/class_img.gif" WIDTH="160" HEIGHT="51"></h2>
<hr size="4" color="#FF0000" width="75%">
<p align="center"><img src="../images/menu_bar_jc_d.gif" WIDTH="150" HEIGHT="35"><img src="../images/dot_blank.gif" name="b1" WIDTH="10" HEIGHT="35"><br>
<a href="../class_api.htm" onMouseOver="switchGraphic('1','b2')" onMouseOut="switchGraphic('0','b2')"><img src="../images/menu_bar_api.gif" border="0" WIDTH="150" HEIGHT="35"></a><img src="../images/dot_blank.gif" name="b2" WIDTH="10" HEIGHT="35"><br>
<span align="center"><a href="../class_wz.htm" onMouseOver="switchGraphic('1','b5')" onMouseOut="switchGraphic('0','b5')"><img src="../images/menu_bar_wz.gif" border="0" WIDTH="150" HEIGHT="35"></a><img src="../images/dot_blank.gif" name="b5" WIDTH="10" HEIGHT="35"></span><br>
<a href="../class_tip.htm" onMouseOver="switchGraphic('1','b3')" onMouseOut="switchGraphic('0','b3')"><img src="../images/menu_bar_tip.gif" border="0" WIDTH="150" HEIGHT="35"></a><img src="../images/dot_blank.gif" name="b3" WIDTH="10" HEIGHT="35"><br>
<a href="../class_fqa.htm" onMouseOver="switchGraphic('1','b4')" onMouseOut="switchGraphic('0','b4')"><img src="../images/menu_bar_end_fqa.gif" border="0" WIDTH="150" HEIGHT="35"></a><img src="../images/dot_blank.gif" name="b4" WIDTH="10" HEIGHT="35"></p>
<p align="center"><a href="../context.htm"><img src="../images/logo_return.jpg" border="0" WIDTH="70" HEIGHT="260"></a></td>
<td width="76%" valign="top" align="center"><div align="center"><center><table border="0" cellpadding="8" cellspacing="0" width="27%" style="background-color: rgb(0,128,128)">
<tr>
<td width="100%" valign="top" align="center"><a name="top"><font size="5" color="#C0C0C0"><strong>VB入门教程</strong></font></a></td>
</tr>
</table>
</center></div><p><a href="class_book_begin061.htm">第一页</a> <a href="class_book_begin062.htm">第二页</a> 第三页 <a href="class_book_begin064.htm">第四页</a><br>
<a href="class_book_begin065.htm">第五页</a> <a href="../class_book.htm">返回</a>
</p>
<div align="center"><center><table border="0" cellpadding="8" cellspacing="0" width="100%">
<tr>
<td width="100%"><font size="3" color="#8000FF"><strong><em>第六章:输入(一)</em></strong></font></td>
</tr>
<tr>
<td width="100%" style="background-color: rgb(232,255,254)"><p ALIGN="JUSTIFY"><font size="3">本例中出现了一个Frame1控件,它是一种框架,可以用来把窗体分成好几个部分,首先应该在窗体上画出Frame1控件,然后再选择相应的控件,在Frame1上描出轮廓,使其是出现在Frame1之上,本例中除去两个按钮,其余都在Frame1上面。本例中用到了几组控件数组,其创建方法是,在选定的点右键,选择Copy,再在窗体其他部位单击右键,选择Paste即可,注意,若要使粘贴的对象在Frame1上,请在Frame1上单击右键选择Paste。</font></p>
<p ALIGN="JUSTIFY"><font size="3">我们通过这个窗体,对输入框进行完整的控制,原理是这样的:当我们把窗体中要填写的对输入框的参数完成后按下OK按钮,就会出现我们设计的那个输入框,我们从输入框退出时则返回我们投票的结果,代码如下.</font></p>
<p ALIGN="JUSTIFY"><font size="3">窗体初次被装入时,Label1(3)、Label(4)和Text1(3)、Text1(4)的Enabled属性都是False,我们需要通过改变Check1的Value(1,被选中,0,未选中)是他们有效或无效。</font></p>
<p ALIGN="JUSTIFY"><font size="3">声明全局变量(General):</font></p>
<p ALIGN="JUSTIFY"><strong><em><font size="3" color="#004080">Dim PosChk As Boolean </font><font size="3" color="#008000">'检查X、Y坐标是否有效</font></em></strong></p>
<p ALIGN="JUSTIFY"><font size="3" color="#000000">Check1_Click 事件:</font></p>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>Private Sub Check1_Click()</em></strong></font></p>
<blockquote>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>If Check1.Value = 1 Then</em></strong></font></p>
<blockquote>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>Label1(3).Enabled = True</em></strong></font></p>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>Label1(4).Enabled = True</em></strong></font></p>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>Text1(3).Enabled = True</em></strong></font></p>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>Text1(4).Enabled = True</em></strong></font></p>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>PosChk = True</em></strong></font></p>
</blockquote>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>Else</em></strong></font></p>
<blockquote>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>Label1(3).Enabled = False</em></strong></font></p>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>Label1(4).Enabled = False</em></strong></font></p>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>Text1(3).Enabled = False</em></strong></font></p>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>Text1(4).Enabled = False</em></strong></font></p>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>PosChk = False</em></strong></font></p>
</blockquote>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>End If</em></strong></font></p>
</blockquote>
<p ALIGN="JUSTIFY"><font size="3" color="#004080"><strong><em>End Sub</em></strong></font></p>
<p ALIGN="JUSTIFY"><font size="3">接着在按钮中填写代码:</font></p>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Private Sub
Command1_Click(Index As Integer)</font></strong></em></p>
<blockquote>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Dim Prompt, Title, Default
As String</font></strong></em></p>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Dim xPos, yPos As Integer</font></strong></em></p>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Select Case Index</font></strong></em></p>
<blockquote>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Case 0</font></strong></em></p>
<blockquote>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Prompt = Text1(0).Text</font></strong></em></p>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Title = Text1(1).Text</font></strong></em></p>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Default = Text1(2).Text</font></strong></em></p>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">If PosChk Then</font></strong></em></p>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">xPos = Val(Text1(3).Text)</font></strong></em></p>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">yPos = Val(Text1(4).Text)</font></strong></em></p>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">a$ = InputBox(Prompt, Title,
Default, xPos, yPos)</font></strong></em></p>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Else</font></strong></em></p>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">a$ = InputBox(Prompt, Title,
Default, xPos, yPos)</font></strong></em></p>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">End If</font></strong></em></p>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Label1(5).Caption = "谢谢您的投票,您的选择是"
& a$ & "!"</font></strong></em></p>
</blockquote>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Case 1</font></strong></em></p>
<blockquote>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">Unload Me</font></strong></em></p>
</blockquote>
</blockquote>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">End Select</font></strong></em></p>
</blockquote>
<p ALIGN="JUSTIFY"><em><strong><font size="3" color="#004080">End Sub</font></strong></em></p>
<p ALIGN="JUSTIFY"><font size="3">按下F5运行程序,你会看到这样的结果。图6-4,6-5。是不是有种受骗的感觉,啊哟哟,可不是我的错,就是这么容易嘛!</font></p>
<p ALIGN="JUSTIFY"><img src="06-04.gif" alt="06-04.gif (1882 字节)" WIDTH="363" HEIGHT="145"><br>
<img src="06-05.gif" alt="06-05.gif (5072 字节)" WIDTH="384" HEIGHT="326"></td>
</tr>
</table>
</center></div><p align="right"><strong><a href="#top"><img src="top2.gif" border="0" WIDTH="27" HEIGHT="30"></a></strong></td>
</tr>
</table>
</center></div>
<p> </p>
</body>
</html>
<!--webbot bot="HTMLMarkup" TAG="XBOT" StartSpan --></SCRIPT><!--webbot BOT="HTMLMarkup" endspan -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -