vel12.htm
来自「简单的说明如何使用VB,非常适合初学使用者,而且是用图表来解说的」· HTM 代码 · 共 2,319 行 · 第 1/4 页
HTM
2,319 行
<HTML><HEAD><TITLE>Visual Basic in 12 Easy Lessons vel12.htm </TITLE><LINK REL="ToC" HREF="index.htm"><LINK REL="Index" HREF="htindex.htm"><LINK REL="Next" HREF="velp06.htm"><LINK REL="Previous" HREF="vel11.htm"></HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080"><A NAME="I0"></A><H2>Visual Basic in 12 Easy Lessons vel12.htm</H2><P ALIGN=LEFT><A HREF="vel11.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="velp06.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="#E68E91" >What You'll Learn</A><LI><A HREF="#E68E92" >Option Buttons Offer Choices</A><LI><A HREF="#E68E93" >Check Boxes Offer More Choices</A><LI><A HREF="#E68E94" >Multiple Sets of Option Buttons</A><LI><A HREF="#E68E95" >Control Arrays Simplify</A><LI><A HREF="#E68E96" >Homework</A><UL><LI><A HREF="#E69E81" >General Knowledge</A><LI><A HREF="#E69E82" >Write Code That...</A><LI><A HREF="#E69E83" >Extra Credit</A></UL></UL></UL></UL><HR ALIGN=CENTER><A NAME="E66E17"></A><H1 ALIGN=CENTER><CENTER><FONT SIZE=6 COLOR="#FF0000"><B>Lesson 6, Unit 12</B></FONT></CENTER></H1><BR><A NAME="E67E20"></A><H2 ALIGN=CENTER><CENTER><FONT SIZE=6 COLOR="#FF0000"><B>Checks, Options, and Control Arrays</B></FONT></CENTER></H2><BR><BR><A NAME="E68E91"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>What You'll Learn</B></FONT></CENTER></H3><BR><UL><LI>Option buttons offer choices<BR><BR><LI>Check boxes offer more choices<BR><BR><LI>Option buttons come in multiple sets<BR><BR><LI>Control arrays simplify programming<BR><BR></UL><P>You'll find that this unit is easy because it introduces two new controls that you've seen in many Windows programs, and it also builds upon arrays that you mastered in the previous unit. The check box and option button controls described here provide the user with choices of data values and options that the user can select. Unlike list and combo box controls, the check box and option button controls (shown in Figure 12.1's Toolbox window) are perfect controls for offering the user a limited number of choices.<BR><P><B> <A HREF="12vel01.gif">Figure 12.1. The check box and option button controls.</A></B><BR><BR><A NAME="E68E92"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Option Buttons Offer Choices</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>The option button control gives the user the ability to select one item from a list of several items that you display in a series of option button choices. Visual Basic keeps the user from selecting more than one option button at a time. The option button's events offer several ways for you to manage the option button selections.<BR><P>List boxes and combo boxes are perfect controls for displaying scrolling lists of items from which the user can select and, in the case of combo boxes, add to. Unlike list and combo boxes, option buttons are good to use when you must offer the user a list of fixed choices that your program knows ahead of time.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>Think of option buttons as a multiple-choice selection from which the user can choose one item.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Option buttons are sometimes called <I>radio buttons</I>. Perhaps you're old enough to remember pre-digital car radios that had five or six buttons sticking out with preset statements assigned to each button. At any one time, you could depress one button because the radio could play only one station at a time. When you pressed a button, any other button pressed inward immediately clicked out. The buttons were designed so that only one button at a time could be chosen.<BR><P>Take the time to load CONTROLS.MAK and press the Next control command button until you see the option buttons shown in Figure 12.2. Try to click more than one option button and you'll see that Visual Basic keeps you from doing so.<BR><P><B> <A HREF="12vel02.gif">Figure 12.2. You may select only one option button at a time.</A></B><BR><P>Table 12.1 lists the property settings for the option button controls that you can set from within the Property window when you place option buttons on the form. There are several properties that you've seen before on other kinds of controls.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 12.1. The option 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>Alignment</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Either 0 for left justification (the default) or 1 for right justification of the option button's caption. If you choose to left justify, the option button appears to the left of the caption. If you choose to right justify, the option button 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 option button. 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 an option button. If you precede any character in the text with an ampersand, &, that character then acts as the option button'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 option button around on the form. (You'll only rarely allow the user to move an option button, 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 option button 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 option 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>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 option button 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 option button.</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 option button is part of a control array, the Index property provides the numeric subscript for each particular option button.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Left</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The number of twips from the left edge of the Form window to the left edge of the option button.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>MousePointer</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The shape that the mouse cursor changes to if the user moves the mouse cursor over the option button. The possible values are from 0 to 12 and represent a range of different shapes that the mouse cursor can take. (See Lesson 12.)</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Name</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The name of the control. By default, Visual Basic generates the names Option1, Option2, and so on as you add subsequent option buttons to the form.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>TabIndex</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The focus tab order begins at 0 and increments every time that you add a new control. You can change the focus order by changing the controls' TabIndex to other values. No two controls on the same form can have the same TabIndex value.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>TabStop</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>If True, the user can press Tab to move the focus to this option button. If False, the option button can't receive the focus.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Tag</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Unused by Visual Basic. This is for the programmer's use for an identifying comment applied to the option button.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Top</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The number of twips from the top edge of an option button to the top of the form.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Value</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Either True or False (the default) indicating whether the option button is selected.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Visible</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>True or False, indicating whether the user can see (and, therefore, use) the option button.</FONT>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?