vel12.htm

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

HTM
2,319
字号
<TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Width</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>The number of twips wide that the option button consumes.</FONT></TABLE><P>Table 12.2 contains a list of the option button's events that trigger event procedures you can write. Generally, the Click event procedure is the most commonly used so that an application can perform a specific action when the user selects a particular option button.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 12.2. The option button's events.</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>Event</I></FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Description</I></FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Click</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the user clicks the option button with the mouse</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>DblClick</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the user double-clicks the mouse over the option button</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>DragDrop</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when a dragging operation over the option button completes</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>DragOver</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs during a drag operation</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>GotFocus</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the option button receives the focus</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>KeyDown</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the user presses a key as long as the KeyPreview property is set to True for the controls on the option button; otherwise, the control gets the KeyDown event</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>KeyPress</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the user presses a key over the option button</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>KeyUp</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the user releases a key</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>LostFocus</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the option button loses the focus</FONT></TABLE><P><FONT COLOR="#FF8000"><B><I>Stop and Type: </I></B></FONT>Load and run this book's project named TRANSL.MAK. Listing 12.1 contains the code for the project's event procedures. The program allows the user to choose the target language into which &quot;Good Morning&quot; is translated. There is room on the form for only one translation, so the option buttons ensure that the user can select one translation at most.<BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>The option button controls enable you to add choices to the form. The user will be allowed to select from at most one choice by clicking (or tabbing to change the focus and pressing Enter) the option button of the desired option. By adding code to the option buttons' Click event procedures, you can respond to the user's choice.<BR><P><FONT COLOR="#000080"><B>Listing 12.1. The </B><B>Form_Load</B><B>()</B><B> and four option button </B><B>Click()</B><B> procedures.</B></FONT><BR><PRE><FONT COLOR="#000080">1: Sub Form_Load ()2: ' Make sure that all option buttons are3: ' False when first displaying the form4: optFre.Value = 05: optIta.Value = 06: optSpa.Value = 07: optPig.Value = 08: End Sub9:10: Sub cmdExit_Click ()11: End12: End Sub13:14: Sub optFre_Click ()15: ' Send the French message16: lblTrans.Caption = &quot;Bonjour&quot;17: End Sub18:19: Sub optIta_Click ()20: ' Send the Italian message21: lblTrans.Caption = &quot;Buon giorno&quot;22: End Sub23:24: Sub optPig_Click ()25: ' Send the Pig latin message26: lblTrans.Caption = &quot;oodGa ayDa&quot;27: End Sub28:29: Sub optSpa_Click ()30: ' Send the Spanish message31: lblTrans.Caption = &quot;Buenos d&igrave;as&quot;32: End Sub</FONT></PRE><P><FONT COLOR="#FF8000"><B><I>Output: </I></B></FONT>Figure 12.3 shows the TRANSL.MAK screen just after the user selects the Italian option button. The Italian translation appears in the shaded label at the bottom of the screen.<BR><P><B> <A HREF="12vel03.gif">Figure 12.3. The user wants to </B><FONT COLOR="#FF8000"><B><I>parla Italiano bene!</A></I></B></FONT><BR><P><FONT COLOR="#FF8000"><B><I>Analysis: </I></B></FONT>Listing 12.1 looks a little different from the other listings that you've seen so far in this book. The listing contains more than one event procedure. As you've gathered by now, a Visual Basic program consists of lots of event procedures and possibly a (general) procedure. In Lesson 8, you'll learn about other kinds of procedures that a Visual Basic program may contain.<BR><P>Although the default Value property for all option buttons is 0, meaning unselected, Visual Basic automatically selects an option button (the one with the lowest TabIndex property value) when loading the application. Therefore, lines 4 through 7 in Listing 12.1 set all four option button Value properties to 0 upon loading the form so that there is no option button set until the user selects one. (The four option buttons are named optFre, optIta, optPig, and optSpa.)<BR><P>Lines 10 through 12 provide the familiar Exit command button event procedure that terminates the program when the user presses the Exit button.<BR><P>Lines 14 through 32 complete the code with the four option button Click event procedures. The user triggers one of the four procedures by selecting one of the four option buttons. The shaded translation label at the bottom of the screen that will hold the translation is named lblTrans. The four option button Click event procedures change the Caption property of the lblTrans object to the appropriate translation that matches the option button's caption.<BR><BR><A NAME="E68E93"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Check Boxes Offer More Choices</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>The check box control works a lot like the option button. You'll place several check boxes on a form; each check box represents a user-selected choice. Unlike option buttons, the user can select more than one check box item at a time.<BR><P>Figure 12.4 contains the check box controls found in this book's CONTROLS.MAK application. If you load and run the program, the check boxes are the fourth set of controls on which you'll click. As you can see from Figure 12.4, when the user selects a check box, the check box is marked with an X, indicating a true selection. Two of the three check boxes are selected in Figure 12.4.<BR><P><B> <A HREF="12vel04.gif">Figure 12.4. The check box controls allow for multiple selections.</A></B><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>Although the check box controls in Figure 12.4 don't contain access keystrokes, you can add access keystroke selection to check boxes just as you can for option button controls.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Table 12.3 contains the property values available for check box controls. Most of the properties are equivalent to the option button properties.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 12.3. The check box 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>Alignment</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Either 0 for left justification (the default) or 1 for right justification of the check box's caption. If you choose to left justify, the check box appears to the left of the caption. If you choose to right justify, the check box appears to the right of the caption.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>BackColor</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>The background color of the check box. This is a hexadecimal number representing one of thousands of possible Windows color values. You'll be able to select from a palette of colors displayed by Visual Basic when you're ready to set the BackColor property. The default background color is the same as the form's default background color.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Caption</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>The text that appears in a check box. If you precede any character in the text with an ampersand, &amp;, that character then acts as the check box's access key.</FONT><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 check box around on the form. (You'll only rarely allow the user too move a check box, so the Drag... property settings aren't usually relevant.)</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>DragMode</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Either contains 1 for manual mouse dragging requirements (the user can press and hold the mouse button while dragging the control) or 0 (the default) for automatic mouse dragging, meaning that the user can't drag the check box but that you, through code, can initiate the dragging if needed.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Enabled</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>If set to True (the default), the check box 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>True (the default) if the Caption is to display in boldfaced characters; False otherwise.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>FontItalic</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>True (the default) if the caption is to display in italicized characters; False otherwise.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>FontName</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>The name of the check box caption's style. Typically, you'll use the name of a Windows TrueType font.</FONT><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><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>FontStrikethru</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>True (the default) if the caption is to display in strikethru letters (characters with a dash through each one); False otherwise.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>FontUnderline</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>True (the default) if the caption is to display in underlined letters; False otherwise.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>ForeColor</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>The hexadecimal color code of the caption text's color.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Height</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>The height, in twips, of the check box.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>HelpContextID</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>If you add advanced, context-sensitive help to your application, the HelpContextID provides the identifying number for the help text.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Index</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>If the check box is part of a control array, the Index property provides the numeric subscript for each particular check box.</FONT><TR>

⌨️ 快捷键说明

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