?? class_book_begin0611.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_begin069.htm">第一頁</a> <a href="class_book_begin0610.htm">第二頁</a> 第三頁 <a href="../class_book.htm">返回</a>
<br>
</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)"><font FACE="宋體" SIZE="3"><p ALIGN="JUSTIFY">列表框(</font><font SIZE="3">ListBox</font><font FACE="宋體" SIZE="3">)和復合列表框(</font><font SIZE="3">ComboBox</font><font FACE="宋體" SIZE="3">)也是我們經常見到的視窗元素,我們從它所列示的條目中選出所需的,兩種列表框只是在外觀上略有不同,但從本質和操作方法來說它們是很相象的,它們也有一些特殊的屬性:</font><font SIZE="3"></p>
<blockquote>
<p ALIGN="JUSTIFY"><font color="#004080">List<font FACE="宋體" SIZE="3">屬性,你可以利于該屬性象列表框或復合列表框中添加條目,但也可以在程序設計中通過</font>AddItem<font FACE="宋體" SIZE="3">方法添加。</font></font></p>
<p ALIGN="JUSTIFY"><font color="#004080">ListCount<font FACE="宋體" SIZE="3">屬性,返回列表框或復合列表框中條目的數目。</font></font></p>
<p ALIGN="JUSTIFY"><font color="#004080">ListIndex<font FACE="宋體" SIZE="3">屬性,表示列表框或復合列表框的第幾項條目。(從</font>0<font FACE="宋體" SIZE="3">到</font>ListCount-1<font FACE="宋體" SIZE="3">)</font></font></p>
<p ALIGN="JUSTIFY"><font color="#004080">Sorted<font FACE="宋體" SIZE="3">屬性,可以通過該屬性對列表框或復合列表框中的條目根據字母順序排序。</font></font></p>
<p ALIGN="JUSTIFY"><font color="#004080">MultiSelect<font FACE="宋體" SIZE="3">屬性,</font>0<font FACE="宋體" SIZE="3">表示不能多選,</font>1<font FACE="宋體" SIZE="3">表示簡單多選,</font>2<font FACE="宋體" SIZE="3">表示寬展多選,僅限于列表框。</font></font></p>
<p ALIGN="JUSTIFY"><font color="#004080">Columns<font FACE="宋體" SIZE="3">屬性,表示條目是以一列顯示還是兩列顯示,僅限于列表框。</font></font></p>
<p ALIGN="JUSTIFY"><font color="#004080">Style</font></font><font FACE="宋體" SIZE="3" color="#004080">屬性:表示列表框或復合列表框以何種風格顯示,二者參數不同。</font><font FACE="宋體" SIZE="3"></p>
</font>
</blockquote>
<font FACE="宋體" SIZE="3"><p ALIGN="JUSTIFY">舉兩個簡單的例子。</p>
<p ALIGN="JUSTIFY">例子一,建立一個新項目文件,在</font><font SIZE="3">Form1</font><font FACE="宋體" SIZE="3">上添加一個</font><font SIZE="3">List</font><font FACE="宋體" SIZE="3">控件,調整適當的尺寸,無需改變任何屬性。填寫以下代碼。</font><font SIZE="3"></p>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">Private Sub Form_Load()</font></strong></em></p>
<blockquote>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">With List1</font></strong></em></p>
<blockquote>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">.AddItem "0-Default"<br>
.AddItem "1-Arrow"<br>
.AddItem "2-Cross"<br>
.AddItem "3-I-Beam"<br>
.AddItem "4-Icon"<br>
.AddItem "5-Size"<br>
.AddItem "6-Size NE SW"<br>
.AddItem "7-Size NS"<br>
.AddItem "8-Size NW SE"<br>
.AddItem "9-Size WE"<br>
.AddItem "10-Up Arrow"<br>
.AddItem "11-Hourglass"<br>
.AddItem "12-NoDrag"<br>
.AddItem "13-Arrow And Hourglass"<br>
.AddItem "14-Arrow And Question"<br>
.AddItem "15-Size All"</font></strong></em></p>
</blockquote>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">End With</font></strong></em></p>
</blockquote>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">End Sub</font></strong></em></p>
<p ALIGN="JUSTIFY"> </p>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">Private Sub List1_Click()</font></strong></em></p>
<blockquote>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080" SIZE="3">MousePointer =
List1.ListIndex</font><font color="#008040">’<font FACE="宋體" SIZE="3">這里的</font>MousePointer<font FACE="宋體" SIZE="3">是窗體全局內的屬性</font></font></strong></em></p>
</blockquote>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">End Sub</font></strong></em></font><font FACE="宋體" SIZE="3"></p>
<p ALIGN="JUSTIFY">當你點在不同項上面鼠標指針也會隨著改變,如圖</font><font SIZE="3">6</font><font FACE="宋體" SIZE="3">-</font><font SIZE="3">14</font><font FACE="宋體" SIZE="3">。</font><font SIZE="3"></p>
<p ALIGN="JUSTIFY"><img src="0614.gif" alt="0614.gif (3321 字節)" WIDTH="320" HEIGHT="240"></p>
<p ALIGN="JUSTIFY">AddItem</font><font FACE="宋體" SIZE="3">方法語法如下:</font><font SIZE="3"></p>
<blockquote>
<p ALIGN="JUSTIFY"><em><strong><font color="#FF0000">ListObject “<font FACE="宋體" SIZE="3">字符串</font>”,</font></font><font FACE="宋體" SIZE="3" color="#FF0000">數值</font></strong></em><font FACE="宋體" SIZE="3"></p>
</font>
</blockquote>
<font FACE="宋體" SIZE="3"><p ALIGN="JUSTIFY">字符串后的數值可以指定條目加入在第幾個條目的位置上,如果沒有的話,添加項將逐次排下去。</p>
<p ALIGN="JUSTIFY">下面舉一個復合列表框的例子,例子通過選擇復合列表框中的選項來改變文本框的字體。請新建一個項目文件,在窗體中添加一個</font><font SIZE="3">ComboBox</font><font FACE="宋體" SIZE="3">(</font><font SIZE="3">Combo1</font><font FACE="宋體" SIZE="3">)和一個</font><font SIZE="3">TextBox</font><font FACE="宋體" SIZE="3">(</font><font SIZE="3">Text1</font><font FACE="宋體" SIZE="3">),添加如下代碼。</font><font SIZE="3"></p>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">Private Sub Combo1_Click()</font></strong></em></p>
<blockquote>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">Text1.FontName =
Combo1.List(Combo1.ListIndex)</font></strong></em></p>
</blockquote>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">End Sub</font></strong></em></p>
<p ALIGN="JUSTIFY"> </p>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">Private Sub Form_Load()</font></strong></em></p>
<blockquote>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">With Combo1</font></strong></em></p>
<blockquote>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080" SIZE="3">.AddItem "</font><font FACE="宋體" SIZE="3" color="#004080">宋體</font><font color="#004080" SIZE="3">"<br>
.AddItem "</font><font FACE="宋體" SIZE="3" color="#004080">隸書</font><font color="#004080" SIZE="3">"<br>
.AddItem "</font><font FACE="宋體" SIZE="3" color="#004080">黑體</font><font color="#004080" SIZE="3">"<br>
.AddItem "</font><font FACE="宋體" SIZE="3" color="#004080">楷體</font><font color="#004080" SIZE="3">"</font><br>
<font color="#004080">.ListIndex = 0</font><font color="#008040">'把第一個條目作為初始項</font></strong></em></p>
</blockquote>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">End With</font></strong></em></p>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080" SIZE="3">Text1.FontSize = 30</font><font color="#008000">’<font FACE="宋體" SIZE="3">放大字體</font></font><br>
<font color="#004080" SIZE="3">Text1.FontName = Combo1.List(0)</font><font color="#008040">’<font FACE="宋體" SIZE="3">初始字體為“宋體”</font></font></strong></em></p>
</blockquote>
<p ALIGN="JUSTIFY"><em><strong><font color="#004080">End Sub</font></strong></em></font><font FACE="宋體" SIZE="3"></p>
<p ALIGN="JUSTIFY">如圖</font><font SIZE="3">6</font><font FACE="宋體" SIZE="3">-</font><font SIZE="3">15</font><font FACE="宋體" SIZE="3">。</p>
<p ALIGN="JUSTIFY"><img src="0615.gif" alt="0615.gif (2935 字節)" WIDTH="320" HEIGHT="240"></p>
<p>(第六章完)</font></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 + -