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

📄 class_book_begin0610.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;}
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_begin0611.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>第六章:输入(三)</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">R</font><font FACE="宋体" SIZE="3">、</font><font SIZE="3">G</font><font FACE="宋体" SIZE="3">、</font><font SIZE="3">B</font><font FACE="宋体" SIZE="3">,滚动滚动条,将在右边的图片框中显示相应的颜色,并且在下面的文本框中显示颜色的十六进制数值。</p>
        <p ALIGN="JUSTIFY">现在,新建一个项目文件,在</font><font SIZE="3">Form1</font><font FACE="宋体" SIZE="3">中如图</font><font SIZE="3">6</font><font FACE="宋体" SIZE="3">-</font><font SIZE="3">12</font><font FACE="宋体" SIZE="3">布局控件,各控件属性如下表:</font></p>
        <p ALIGN="JUSTIFY"><img src="0612.gif" alt="0612.gif (3568 字节)" WIDTH="345" HEIGHT="267"></p>
        <table BORDER="1" CELLSPACING="1" CELLPADDING="7" WIDTH="379">
          <tr>
            <td WIDTH="46%" VALIGN="TOP"><font SIZE="3"><p ALIGN="JUSTIFY">HsrollBar</font></td>
            <td WIDTH="54%" VALIGN="TOP"><font SIZE="3"><p ALIGN="JUSTIFY">Name Hscroll1</p>
            <p ALIGN="JUSTIFY">Index 0</font><font FACE="宋体" SIZE="3">、</font><font SIZE="3">1</font><font FACE="宋体" SIZE="3">、</font><font SIZE="3">2</p>
            </font><font FACE="宋体" SIZE="3"><p ALIGN="JUSTIFY">(共同属性)</p>
            </font><font SIZE="3"><p ALIGN="JUSTIFY">Max 255</p>
            <p ALIGN="JUSTIFY">Min 0</p>
            <p ALIGN="JUSTIFY">LargeChange 10</p>
            <p ALIGN="JUSTIFY">SmallChange 1</font></td>
          </tr>
          <tr>
            <td WIDTH="46%" VALIGN="TOP"><font SIZE="3"><p ALIGN="JUSTIFY">Label</font></td>
            <td WIDTH="54%" VALIGN="TOP"><font SIZE="3"><p ALIGN="JUSTIFY">Name Label1</p>
            <p ALIGN="JUSTIFY">Index 0</font><font FACE="宋体" SIZE="3">、</font><font SIZE="3">1</font><font FACE="宋体" SIZE="3">、</font><font SIZE="3">2</p>
            <p ALIGN="JUSTIFY">Index 0 Caption </font><font FACE="宋体" SIZE="3">“红:”</font><font SIZE="3"> </p>
            <p ALIGN="JUSTIFY">Index 1 Caption </font><font FACE="宋体" SIZE="3">“绿:”</p>
            </font><font SIZE="3"><p ALIGN="JUSTIFY">Index 2 Caption </font><font FACE="宋体" SIZE="3">“蓝:”</font></td>
          </tr>
          <tr>
            <td WIDTH="46%" VALIGN="TOP"><font SIZE="3"><p ALIGN="JUSTIFY">Label</font></td>
            <td WIDTH="54%" VALIGN="TOP"><font SIZE="3"><p ALIGN="JUSTIFY">Name Label2</p>
            <p ALIGN="JUSTIFY">Caption </font><font FACE="宋体" SIZE="3">“颜色值”</font></td>
          </tr>
          <tr>
            <td WIDTH="46%" VALIGN="TOP"><font SIZE="3"><p ALIGN="JUSTIFY">TextBox</font></td>
            <td WIDTH="54%" VALIGN="TOP"><font SIZE="3"><p ALIGN="JUSTIFY">Name Text1</p>
            <p ALIGN="JUSTIFY">Text </font><font FACE="宋体" SIZE="3">“”</font></td>
          </tr>
          <tr>
            <td WIDTH="46%" VALIGN="TOP"><font SIZE="3"><p ALIGN="JUSTIFY">PictureBox</font></td>
            <td WIDTH="54%" VALIGN="TOP"><font SIZE="3"><p ALIGN="JUSTIFY">Name Picuture1</font></td>
          </tr>
        </table>
        <p><font FACE="宋体" SIZE="3"> </p>
        <p ALIGN="JUSTIFY">为了把十进制数值换成十六进制数值,要使用一个叫做</font><font SIZE="3">Hex</font><font FACE="宋体" SIZE="3">()的函数,它把十进制数值转化为十六进制的字符,但对于只有一位的十六进制字符,这个函数并不在高位补零,为了视觉上的正确,我设计了一个小函数帮助它给一位的十六进制字符补零</font><font SIZE="3">.</font><font FACE="宋体" SIZE="3"></p>
        <p ALIGN="JUSTIFY">程序代码很简单,见下:</font><font SIZE="3"></p>
        <p ALIGN="JUSTIFY"></font><em><strong><font color="#004080" SIZE="3">Dim RedStr, GreenStr, 
        BlueStr As String</font><font color="#008000"><font SIZE="3">’RGB</font><font FACE="宋体" SIZE="3">的字符</font></font><font color="#004080"><br>
        </font><font color="#004080" SIZE="3">Dim RedNum, GreenNum, BlueNum As Integer</font><font color="#008000" SIZE="3">’RGB</font><font FACE="宋体" SIZE="3" color="#008000">的数值</font></strong></em><font SIZE="3"></p>
        </font><font FACE="宋体" SIZE="3"><p ALIGN="JUSTIFY"></font><font SIZE="3"> </p>
        <p ALIGN="JUSTIFY"><em><strong><font color="#004080">Function GetColorValue() As String</font></strong></em></p>
        <blockquote>
          <p ALIGN="JUSTIFY"><em><strong><font color="#008040"><font SIZE="3">‘</font><font FACE="宋体" SIZE="3">获得输入值</font></font><br>
          <font color="#004080">RedNum = HScroll1(0).Value<br>
          GreenNum = HScroll1(1).Value<br>
          BlueNum = HScroll1(2).Value</font></strong></em></p>
          <p ALIGN="JUSTIFY"><em><strong><font color="#004080">RedStr = Hex(RedNum)</font><br>
          <font color="#004080" SIZE="3">If Len(RedStr) &lt; 2 Then RedStr = &quot;0&quot; + RedStr</font><font color="#008040"><font SIZE="3">’</font><font FACE="宋体" SIZE="3">补零</font></font></strong></em></p>
          <p ALIGN="JUSTIFY"><em><strong><font color="#004080">GreenStr = Hex(GreenNum)<br>
          If Len(GreenStr) &lt; 2 Then GreenStr = &quot;0&quot; + GreenStr</font></strong></em></p>
          <p ALIGN="JUSTIFY"><em><strong><font color="#004080">BlueStr = Hex(BlueNum)<br>
          If Len(BlueStr) &lt; 2 Then BlueStr = &quot;0&quot; + BlueStr</font></strong></em></p>
          <p ALIGN="JUSTIFY"><em><strong><font color="#004080" SIZE="3">GetColorValue = RedStr + 
          GreenStr + BlueStr</font><font color="#008040"><font SIZE="3">’</font><font FACE="宋体" SIZE="3">合并</font></font></strong></em></p>
        </blockquote>
        <p ALIGN="JUSTIFY"><em><strong><font color="#004080">End Function</font></strong></em></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="#008040" SIZE="3">‘</font><font FACE="宋体" SIZE="3" color="#008040">初始化程序</font><br>
          <font color="#004080">Text1.Text = GetColorValue<br>
          Picture1.BackColor = RGB(RedNum, GreenNum, BlueNum)</font><font color="#008040">'RGB函数返回颜色值</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 HScroll1_Change(Index As 
        Integer)</font></strong></em></p>
        <blockquote>
          <p ALIGN="JUSTIFY"><em><strong><font color="#008000" SIZE="3">‘</font><font FACE="宋体" SIZE="3" color="#008000">当滚动条被改变时</font><br>
          <font color="#004080">Text1.Text = GetColorValue<br>
          Picture1.BackColor = RGB(RedNum, GreenNum, BlueNum)</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">13</font><font FACE="宋体" SIZE="3">。</p>
        <p ALIGN="JUSTIFY"><img src="0613.gif" alt="0613.gif (3820 字节)" WIDTH="345" HEIGHT="267"></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 + -