📄 class_book_begin021.htm
字号:
<tr>
<td width="100%"><font size="3" color="#8000FF"><strong><em>第二章:事件、属性及数据类型(1)</em></strong></font></td>
</tr>
<tr>
<td width="100%" style="background-color: rgb(232,255,254)"><font FACE="宋体" SIZE="3"><p ALIGN="JUSTIFY">以后两章可能会比较枯燥,但不可否认也很重要,所以为了学好<font size="3">VB</font>,我们一定要打好基础才行。</p>
<p ALIGN="JUSTIFY">一、事件</p>
<p ALIGN="JUSTIFY">通过上一章的例子,你可能对“面向对象的编程”已经有了一定了解,它是由事件驱动的,对于不同的对象,所能感应到的事件也会不同,譬如说当你把鼠标移进某一区域时就会触发</font><font size="3">MouseMove</font><font FACE="宋体" SIZE="3">事件,这很直观,也容易理解,但也有些事件比较抽象,下面我来对一般的事件进行一下解释。</p>
<ol>
<li>窗体和图象框类事件</font></li>
</ol>
<table border="0" cellpadding="0" cellspacing="0" width="100%" msimagelist>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">Paint</font><font FACE="宋体" SIZE="3">事件:当某一对象在屏幕中被移动,改变尺寸或清除后,程序会自动调用</font><font size="3">Paint</font><font FACE="宋体" SIZE="3">事件。</font><strong><em><font color="#FF0000" FACE="宋体" SIZE="3">注意:当对象的</font><font color="#FF0000"><font size="3">AutoDraw</font><font FACE="宋体" SIZE="3">属性为</font><font size="3">True</font><font FACE="宋体" SIZE="3">(-</font><font size="3">1</font><font FACE="宋体" SIZE="3">)时,程序不会调用</font><font size="3">Paint</font></font><font color="#FF0000" FACE="宋体" SIZE="3">事件。</font></em></strong></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">Resize</font><font FACE="宋体" SIZE="3">事件:当对象的大小改变时触发</font><font size="3">Resize</font><font FACE="宋体" SIZE="3">事件。</font></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">Load</font><font FACE="宋体" SIZE="3">事件:仅适用于窗体对象,当窗体被装载时运行。</font></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">Unload</font><font FACE="宋体" SIZE="3">事件:仅适用于窗体对象,当窗体被卸载时运行。</font></td msimagelist>
</tr>
</table msimagelist>
<p> 2.当前光标(<font size="3">Focus</font>)事件</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%" msimagelist>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">GotFocus</font><font FACE="宋体" SIZE="3">事件:当光标聚焦于该对象时发生事件。</font></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">LostFocus</font><font FACE="宋体" SIZE="3">事件:当光标离开该对象时发生事件。</font></td msimagelist>
</tr>
</table msimagelist>
<blockquote>
<blockquote>
<p ALIGN="JUSTIFY"><strong><em><font color="#FF0000" FACE="宋体" SIZE="3">注意:</font><font color="#FF0000"><font size="3">Focus</font><font FACE="宋体" SIZE="3">英文为“焦点”、“聚焦”之意,最直观的例子是,比如有两个窗体,互相有一部分遮盖,当你点下面的窗体时,它就会全部显示出来,这时它处在被激活的状态,并且标题条变成蓝色,这就是</font><font size="3">GotFocus</font><font FACE="宋体" SIZE="3">事件,而相反,另外一个窗体被遮盖,并且标题条变灰,称为</font><font size="3">LostFocus</font></font><font color="#FF0000" FACE="宋体" SIZE="3">事件。上面所说的“光标”并非指鼠标指针。</font></em></strong><font FACE="宋体" SIZE="3"></p>
</blockquote>
</blockquote>
<p> 3.鼠标操作事件</p>
</font><table border="0" cellpadding="0" cellspacing="0" width="100%" msimagelist>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">Click</font><font FACE="宋体" SIZE="3">事件:鼠标单击对象。</font></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">DbClick</font><font FACE="宋体" SIZE="3">事件:鼠标双击事件。</font></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">MouseDown</font><font FACE="宋体" SIZE="3">、</font><font size="3">MouseUp</font><font FACE="宋体" SIZE="3">属性:按下</font><font size="3">/</font><font FACE="宋体" SIZE="3">放开鼠标键事件。</font></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">MouseMove</font><font FACE="宋体" SIZE="3">事件:鼠标移动事件。</font></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">DragDrop</font><font FACE="宋体" SIZE="3">事件:拖放事件,相当于</font><font size="3">MouseDown</font><font FACE="宋体" SIZE="3">、</font><font size="3">MouseMove</font><font FACE="宋体" SIZE="3">和</font><font size="3">MouseUp</font><font FACE="宋体" SIZE="3">的组合。</font></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">DragOver</font><font FACE="宋体" SIZE="3">事件:鼠标在拖放过程中就会产生</font><font size="3">DragOver</font><font FACE="宋体" SIZE="3">事件。</font></td msimagelist>
</tr>
</table msimagelist>
<p> 4.键盘操作属性</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%" msimagelist>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">KeyDown</font><font FACE="宋体" SIZE="3">、</font><font size="3">KeyUp</font><font FACE="宋体" SIZE="3">事件:按键的按下</font><font size="3">/</font><font FACE="宋体" SIZE="3">放开事件。</font></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">KeyPress</font><font FACE="宋体" SIZE="3">事件:按键事件。</font></td msimagelist>
</tr>
</table msimagelist>
<p> 5.改变控制项事件</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%" msimagelist>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">Change</font><font FACE="宋体" SIZE="3">事件:当对象的内容发生改变时,触发</font><font size="3">Change</font><font FACE="宋体" SIZE="3">事件。最典型的例子是文本框(</font><font size="3">TextBox</font><font FACE="宋体" SIZE="3">)。</font></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">DropDown</font><font FACE="宋体" SIZE="3">事件:下弹事件,仅用于组合框(</font><font size="3">ComboBox</font><font FACE="宋体" SIZE="3">)对象。</font></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">PathChange</font><font FACE="宋体" SIZE="3">事件:路径改变事件,仅用于文件列表框(</font><font size="3">FileBox</font><font FACE="宋体" SIZE="3">)对象。</font></td msimagelist>
</tr>
</table msimagelist>
<p> 6.其他事件</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%" msimagelist>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="commbull.gif" width="16" height="17" hspace="13"></td>
<td valign="top" width="100%"><font size="3">Timer</font><font FACE="宋体" SIZE="3">事件:仅用于计时器,每隔一段时间被触发一次。</font></td msimagelist>
</tr>
</table msimagelist>
<blockquote>
<p ALIGN="JUSTIFY">二、属性</p>
</blockquote>
<p ALIGN="JUSTIFY"> 每个对象都有它的属性,并且“<font size="3">Name</font><font FACE="宋体" SIZE="3">”属性是共有的,有了“</font><font size="3">Name</font><font FACE="宋体" SIZE="3">”属性才可以在程序中进行调用。对于属性,可以在窗体的布局操作中完成,也可以在程序运行中改变,这取决你的需要,但有些属性是只读的,它只能在控件布局时改变。我将在以后的实例中具体介绍各个属性的作用。</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 + -