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

📄 class_book_begin042.htm

📁 vb实例,很好很好用的哦,处学者的天堂这是第四部分
💻 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;}
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_begin041.htm">第一页</a> 第二页 <a href="class_book_begin043.htm">第三页</a> <a href="class_book_begin044.htm">第四页</a><br>
    <a href="class_book_begin045.htm">第五页</a> <a href="class_book_begin046.htm">第六页</a> 
    <a href="class_book_begin047.htm">第七页</a> <a href="../class_book.htm">返回</a> 
    &nbsp; <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>第四章:按钮(2)</em></strong></font></td>
      </tr>
      <tr>
        <td width="100%" style="background-color: rgb(232,255,254)"> <p ALIGN="JUSTIFY"><strong>上面举了一个比较简单的例子,下面的例子稍微复杂些:</strong></p>
        <p ALIGN="JUSTIFY"><strong>新建窗体,控件布局如图4-3所示,包括一个List控件,一个Text控件和两个按钮(Command1和Command2),(比较简单的程序我们都采用缺省名),对它们属性做如下修改:</strong></p>
        <p ALIGN="JUSTIFY"><img src="0403.gif" alt="04-03.gif (2583 字节)" WIDTH="320" HEIGHT="240"></p>
        <table BORDER="1" CELLSPACING="1" CELLPADDING="7" WIDTH="283">
          <tr>
            <td WIDTH="28%" VALIGN="TOP"><p ALIGN="JUSTIFY"><strong>List1 </strong></td>
            <td WIDTH="72%" VALIGN="TOP"><p ALIGN="JUSTIFY"><strong>Caption=“请输入你的名字”</strong></td>
          </tr>
          <tr>
            <td WIDTH="28%" VALIGN="TOP"><p ALIGN="JUSTIFY"><strong>Text1 </strong></td>
            <td WIDTH="72%" VALIGN="TOP"><p ALIGN="JUSTIFY"><strong>Text=“”(空字符串)</strong></td>
          </tr>
          <tr>
            <td WIDTH="28%" VALIGN="TOP"><p ALIGN="JUSTIFY"><strong>Button1 </strong></td>
            <td WIDTH="72%" VALIGN="TOP"><p ALIGN="JUSTIFY"><strong>Caption=“复原”</strong></p>
            <p ALIGN="JUSTIFY"><strong>Enabled=False</strong></td>
          </tr>
          <tr>
            <td WIDTH="28%" VALIGN="TOP"><p ALIGN="JUSTIFY"><strong>Button2</strong></td>
            <td WIDTH="72%" VALIGN="TOP"><p ALIGN="JUSTIFY"><strong>Caption=“清除”</strong></td>
          </tr>
        </table>
        <p ALIGN="JUSTIFY"><strong>把使用Button1的Enabled属性设为False(假),是使程序在初始时,无法单击Command1。按F5,运行程序,图4-4,复原按钮成为灰色,不可选。</strong></p>
        <p ALIGN="JUSTIFY"><img src="0404.gif" alt="04-04.gif (2517 字节)" WIDTH="320" HEIGHT="240"></p>
        <p ALIGN="JUSTIFY"><strong>当然现在程序还什么也不能做,下面我们在程序中添加代码:</strong></p>
        <p ALIGN="JUSTIFY"><strong>首先在General里声明全局变量:</strong></p>
        <p ALIGN="JUSTIFY"><strong><font color="#004080">Dim StoreString As String</font><font color="#008000"> '用来储存字符串</font></strong></p>
        <p ALIGN="JUSTIFY"><font color="#FF0000"><strong>※注意:为什么用全局变量?</strong></font></p>
        <p ALIGN="JUSTIFY"><strong>VB里每一个小过程都相当于一个程序,程序里的变量称为局部变量,是只能在程序内部使用的,而当程序调用结束后,由于从内存中被清除,所以变量储存的值也就消失了,这里的全局变量是用来在过程中传递字符串。</strong></p>
        <p ALIGN="JUSTIFY"><strong>接着填写以下代码:</strong></p>
        <p ALIGN="JUSTIFY"><font color="#004080"><strong>Private Sub Command1_Click()</strong></font></p>
        <blockquote>
          <p ALIGN="JUSTIFY"><font color="#004080"><strong>Text1.Text = StoreString<br>
          Command1.Enabled = False</strong></font></p>
        </blockquote>
        <p ALIGN="JUSTIFY"><font color="#004080"><strong>End Sub</strong></font></p>
        <p ALIGN="JUSTIFY"> </p>
        <p ALIGN="JUSTIFY"><font color="#004080"><strong>Private Sub Command2_Click()</strong></font></p>
        <blockquote>
          <p ALIGN="JUSTIFY"><strong><font color="#004080">StoreString = Text1.Text<br>
          Text1.Text = &quot;&quot; </font><font color="#008040">'清除</font><font color="#004080"><br>
          Command1.Enabled = True</font></strong></p>
        </blockquote>
        <p ALIGN="JUSTIFY"><font color="#004080"><strong>End Sub</strong></font></p>
        <p ALIGN="JUSTIFY"><strong>运行程序,如图4-5。按下“清除”,文本框被清除,按下“复原”,文本有被恢复,许多程序中的Undo/Redo就是利用这个原理实现的,现在知道为什么内存越多越好了吧。</strong></p>
        <p ALIGN="JUSTIFY"><img src="0405.gif" alt="04-05.gif (2637 字节)" WIDTH="320" HEIGHT="240"></p>
        <p ALIGN="JUSTIFY"><strong>我们在把程序修改一下,把Button2删除,Button1的Enabled属性改为True,Caption改为“清除”,填写代码:</strong></p>
        <p ALIGN="JUSTIFY"><font color="#004080"><strong>Private Sub Command1_Click()</strong></font></p>
        <blockquote>
          <p ALIGN="JUSTIFY"><font color="#004080"><strong>If Command1.Caption = &quot;清除&quot; 
          Then</strong></font></p>
          <blockquote>
            <p ALIGN="JUSTIFY"><strong><font color="#004080">StoreString = Text1.Text<br>
            Text1.Text = &quot;&quot; </font><font color="#008040">'清除</font><font color="#004080"><br>
            Command1.Caption = &quot;复原&quot;</font></strong></p>
          </blockquote>
          <p ALIGN="JUSTIFY"><font color="#004080"><strong>Else</strong></font></p>
          <blockquote>
            <p ALIGN="JUSTIFY"><font color="#004080"><strong>Text1.Text = StoreString<br>
            Command1.Caption = &quot;清除&quot;</strong></font></p>
          </blockquote>
          <p ALIGN="JUSTIFY"><font color="#004080"><strong>End If</strong></font></p>
        </blockquote>
        <p ALIGN="JUSTIFY"><font color="#004080"><strong>End Sub</strong></font></p>
        <p ALIGN="JUSTIFY"><strong>同样可以上面的功能,但是却少用了一个控件,控件使用少的程序启动会快些。</strong></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 + -