vel05.htm

来自「简单的说明如何使用VB,非常适合初学使用者,而且是用图表来解说的」· HTM 代码 · 共 2,465 行 · 第 1/4 页

HTM
2,465
字号
<HTML><HEAD><TITLE>Visual Basic in 12 Easy Lessons vel05.htm </TITLE><LINK REL="ToC" HREF="index.htm"><LINK REL="Index" HREF="htindex.htm"><LINK REL="Next" HREF="vel06.htm"><LINK REL="Previous" HREF="velp02.htm"></HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080"><A NAME="I0"></A><H2>Visual Basic in 12 Easy Lessons vel05.htm</H2><P ALIGN=LEFT><A HREF="velp02.htm" TARGET="_self"><IMG SRC="purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A><A HREF="index.htm" TARGET="_self"><IMG SRC="purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A><A HREF="vel06.htm" TARGET="_self"><IMG SRC="purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A><HR ALIGN=CENTER><P><UL><UL><UL><LI><A HREF="#E68E40" >What You'll Learn</A><LI><A HREF="#E68E41" >Focus In on Controls</A><LI><A HREF="#E68E42" >The Command Button</A><LI><A HREF="#E68E43" >Label Properties</A><LI><A HREF="#E68E44" >Text Box Controls</A><LI><A HREF="#E68E45" >Setting Properties</A><LI><A HREF="#E68E46" >Homework</A><UL><LI><A HREF="#E69E38" >General Knowledge</A><LI><A HREF="#E69E39" >Write Code That...</A><LI><A HREF="#E69E40" >Find the Bug</A><LI><A HREF="#E69E41" >Extra Credit</A></UL></UL></UL></UL><HR ALIGN=CENTER><A NAME="E66E7"></A><H1 ALIGN=CENTER><CENTER><FONT SIZE=6 COLOR="#FF0000"><B>Lesson 3, Unit 5</B></FONT></CENTER></H1><BR><A NAME="E67E10"></A><H2 ALIGN=CENTER><CENTER><FONT SIZE=6 COLOR="#FF0000"><B>Using Labels, Buttons, and Text Boxes</B></FONT></CENTER></H2><BR><BR><A NAME="E68E40"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>What You'll Learn</B></FONT></CENTER></H3><BR><UL><LI> [lb] The focus and controls<BR><BR><LI> [lb] The command button<BR><BR><LI> [lb] Label Properties<BR><BR><LI> [lb] Text box controls<BR><BR><LI> [lb] Setting properties<BR><BR></UL><P>This unit explores labels, command buttons, and text boxes in detail. It explains all the properties associated with those controls. The important thing to remember as you wade through the tables of properties is that you need to master these properties if you are going to master Visual Basic. Unless you understand how to set up each property to respond in the manner your application requires, you cannot use Visual Basic effectively or create the outstanding applications that Visual Basic is capable of creating. Once you learn about the properties available for these controls, the next unit will explain all the event procedures that are possible with the command button, label, and text box controls.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>From this unit through the end of the book, each lesson's project contains a complete application that uses the concepts taught in the two units. Each unit is descriptive, and the project takes what you learned in the two units and shows you what a real-world application of the material looks like. You get the best of both worlds of teaching: The theory comes in the units, and the practical applications appear in the end-of-lesson projects.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><BR><A NAME="E68E41"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Focus In on Controls</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>As you learn about controls, you often hear the term <I>focus</I>. Learning about focus now saves you a lot of trouble later.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><I>Definition: Focus</I> refers to the control that is currently highlighted.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>The control with the focus is the next control that will accept the user's response. Most Windows users instinctively understand focus even though very few have thought much about focus. The control with the focus is always the control that is highlighted. The focus often moves from control to control as the user works. The focus determines where the next action will take place.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>In a way, a control's focus is much like a word processor's text cursor. The focus enables the user to know where the next action will take place unless he changes the focus, just as a text cursor tells the user where the next character will appear unless he moves the text cursor to a different location.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Only one control can have the focus at any one time, and not every control can get the focus. Figure 5.1 shows a form with four command buttons. The Third command button has the focus. You can tell this because the Third command button is highlighted, whereas the other command buttons are not. Not only is the button highlighted, but there is a dotted line around its caption.<BR><P><B> <A HREF="05vel01.gif">Figure 5.1. The </B><B>T</B><B>hird command button has the </B><B>focus.</A></B><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><I>Definition: </I>The <I>focus order</I> determines the control next in line for the focus.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Every form has a focus order that determines the next control that will receive the focus. In Figure 5.1, if the user presses Enter, the figure's Third command button will depress only because it has the focus. If the user pressed Tab before pressing Enter, the next control in sequence to receive the focus would be highlighted. If the Second command button were next in sequence to gain the focus, the user's Tab press would highlight the Second command button.<BR><P>When you see a dialog box such as a File Open dialog box, the OK button is almost always the command button that has the focus. You can press Enter to select the OK command button, click a different command button (such as a Cancel command button), or press Tab until the command button that you want has the focus.<BR><P>Through property settings, you can determine the focus order and whether a control can receive the focus. Your form might have some controls that you don't want the user to be able to highlight; therefore, you prevent them from getting the focus.<BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>The focus determines the control that triggers next. If a command button has the focus, it is highlighted and is the next button chosen if the user presses Enter. If a text box has the focus, it will receive the next keystroke's character even if there are five other text box controls on the form at the same time. If the user needs to enter text in a certain text box that does not have the focus, he must press Tab until the text box gets the focus, or he must click the text box that he wants with the mouse cursor.<BR><BR><A NAME="E68E42"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>The Command Button</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>The command button is the cornerstone of most Windows applications. With the command button, your user can respond to events, signal when something is ready for printing, and tell the program when to terminate. Although all command buttons work in the same fundamental way&#151;they visually depress when the user clicks them, and they trigger events such as Click events&#151;numerous properties for command buttons uniquely define each one and its behavior.<BR><P>You are already familiar with several command button properties. You have seen that command buttons vary in size and location. Table 5.1 describes all the command button properties. You might want to open a new project, add a command button to the Form window by double-clicking the command button on the toolbox, and press F4 to scroll through the Properties window.<BR><P>Several of the property settings can accept a limited range of numeric values. Most of these values are named in CONSTANT.TXT, and they are mentioned in this book as well. Some property settings accept either True or False values, indicating a yes or no condition. For example, if the Cancel property is set to True, that command button is the cancel command button and all other command buttons must contain a False Cancel property because only one command button on a form can have a True Cancel property.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>As you read through the property tables in this book, familiarize yourself not only with the purpose of each property but also with its name. When you write code, you need to refer to these properties by their full and exact names.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 5.1. Command button properties.</B></FONT></CENTER><BR><TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 ><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Property</I></FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Description</I></FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>BackColor</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>The command button is one of the few controls for which the background color property means very little. When you change the background color, only the dotted line around the command button's caption changes color.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Cancel</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>If True, Visual Basic automatically clicks this command button when the user presses Esc. Only one command button can have a True Cancel property value at a time. All command buttons initially have their Cancel property set to False.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Caption</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>The text that appears on the command button. If you precede any character in the text with an ampersand (&amp;),it acts as the access key. Therefore, the access key for a command button with a Caption property set to E&amp;xit is Alt+X. The default Caption value is the command button's Name value.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Default</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>The command button with the initial focus when the form first activates has a Default property setting of True. All command buttons initially have False Default property values until you change one of them.</FONT></TABLE><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><I>Definition: </I>An <I>icon</I> is a picture on the screen.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 ><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>DragIcon</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>The icon that appears when the user drags the command button around on the form.</FONT></TABLE><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE>Because you only rarely enable the to user move a command button, you won&#146;t use the Drag... property settings very much.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 ><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>DragMode</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Contains either 1 for manual mouse dragging requirements&#151;the user can press and hold the mouse button while dragging the control&#151;or 0 (the default) for automatic mouse dragging&#151;the user cannot drag the command button, but through code you can initiate the dragging if needed.</FONT></TABLE><TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 ><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Enabled</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>If True (the default), the command button can respond to events. Otherwise, Visual Basic halts event processing for that particular control.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>FontBold</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>If True (the default), the Caption displays in boldfaced characters.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>FontItalic</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>If True (the default), the caption displays in italicized characters.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>FontName</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>The name of the style of the command button caption. You typically use the name of a Windows True Type font.</FONT></TABLE><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE>(margin)<I>Definition: </I>A <I>point</I> is 1/72 of one inch.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 ><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>FontSize</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>The size, in points, of the font used for the command button's caption.</FONT></TABLE><TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 ><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>FontStrikethru</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>If True (the default), the caption displays in strikethrough letters. In other words, characters have a line drawn through them.</FONT><TR><TD VALIGN=top  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?