vel03.htm
来自「简单的说明如何使用VB,非常适合初学使用者,而且是用图表来解说的」· HTM 代码 · 共 1,384 行 · 第 1/3 页
HTM
1,384 行
<BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>The label control is one of the simplest controls to work with. With the label control, you can add descriptive text to the form in any location by using different styles and sizes of fonts.<BR><P>The label control, appearing on the Toolbox window with a capital letter <I>A,</I> holds text. The user sees the text on the resulting application. The title of the CONTROLS.MAK application, Have fun with controls! is placed on the form with the label control.<BR><P>As you will see as you progress through this book, you can set several property values as you place controls. You manage the size of the control and the way the control looks. You can specify a large font size or a small font size, a font style based on any available font style in your Windows system, whether you want the font boldfaced, italicized, or struck through with the strikethrough font style, where the text has a straight line drawn through it.<BR><P>You can draw a box around the label and shade its background any color that you want. Look again at the running program. You can see a command button labeled Next Control. Click this command button with the mouse or press Alt+C. Two new labels will appear in the middle of the screen, as shown in Figure 3.4.<BR><P><B> <A HREF="03vel04.gif">Figure 3.4. Two additional label controls appear </B><B>in the center of the form.</A></B><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>If a command button contains an underlined character—for example, the Next Control command button at the right edge of the program window in Figure 3.4—the underlined character represents the shortcut access keystroke. You can combine the Alt key with the shortcut access key to trigger a press of the command button.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Warning: </B>The user cannot change the text on a label directly. Through code, you can change the label's text in response to a user's action when the need arises. Generally, however, you will set the text within a label when you design the program.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>The label control is one of the easiest controls to add to your applications. Whenever you need to display text within a title or a description for another control, the label control enables you to display the text with various font sizes and styles.<BR><BR><A NAME="E68E24"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>The Text Box Control</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>Unlike the label control, the user can change values within a text box control. You can get answers from the user by using text box controls.<BR><P>When you click the Next Control command button on the running program, the labels that you displayed earlier disappear and a text box appears in their place, as shown in Figure 3.5.<BR><P><B> <A HREF="03vel05.gif">Figure 3.5. The user can change the text within a </B><B>text box.</A></B><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>If you display a text box that has no initial text within it, the user can type text in the text box control in response to a question that you ask. Sometimes, however, you will display initial text within the text box that the user can use as a default value, changing the text only if the default is not the needed value.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Click the mouse cursor anywhere within the Change this! text box. Type new text in the box. Type lots of text in the text box. The text scrolls to the right to accommodate the new text. You can use the arrow keys to move the cursor back and forth within the text box. Also, the Ins and Del keys work just as they do in a word processor. With these two keys, you can insert and delete text from the text box.<BR><P>The text box control—the control with the lowercase ab enclosed in a box—enables you to set an initial value and to control how the text's font style and size appear when the user sees or enters text in the text box. You can control whether the text box contains horizontal and vertical scroll bars so that the user can scroll through the text with scroll bars or with the regular arrow keys.<BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>When the user must enter new text or change existing text, use the text box control to place an area on the screen for the user's keystrokes. The text box control works just like a mini word processor.<BR><BR><A NAME="E68E25"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Command Buttons are Fun!</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>You have seen command buttons in almost every Windows program, including Visual Basic and the currently-running CONTROLS.MAK application. Command buttons give users push-button access to events that you place within an application.<BR><P>A command button appears on the screen just as push buttons appear on a VCR or on your keyboard. The CONTROLS.MAK program contains two command buttons that stay on the screen at all times: The Next Control command button and the Exit command button. As you already know, you can trigger a command button's press with a mouse click or with a shortcut access keystroke.<BR><P>Press the Next Control command button now to see a third command button replace the text box control in the middle of the screen of the running CONTROLS.MAK application. Figure 3.6 shows the screen after the command button is displayed.<BR><P><B> <A HREF="03vel06.gif">Figure 3.6. A command button controlled by the </B><B>program.</A></B><BR><P>Virtually anything can happen when the user clicks a command button. You, the programmer, control exactly what happens. Go ahead and press the CONTROLS.MAK command button. Look—and listen to—what happens. The computer beeps, and the command button’s caption changes from Press Me to Once Again. Press the command button again to hear the beep once more and to restore the command button to its original Press Me state.<BR><P>You set the command button's caption usually when that you design and write a program. As you can see, you can write the program so that the command button's caption changes when the user clicks the button.<BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>A Windows application without command buttons is like day without night. (Okay, that's exaggerating.) Command buttons supply push button access to events that you want the user to trigger.<BR><BR><A NAME="E68E26"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Check Box Controls</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>Check box controls offer multiple-choice values from which the user can select. Once the user selects one or more check boxes, your program can analyze the selected check boxes and make decisions based on those responses.<BR><P>Click the Next Control command button to see the list of three check box values shown in Figure 3.7. The check boxes offer the user a way to select one or more values from a list of values that you display.<BR><P><B> <A HREF="03vel07.gif">Figure 3.7. Two of the three check boxes are </B><B>selected.</A></B><BR><P>With the mouse, click the first and last check boxes on the running CONTROLS.MAK application, as shown in Figure 3.7. When you select a check box, the boxes to the left of the descriptions fills with an X.<BR><P>Once you click these two controls, the two values are said to be <I>selected,</I> and the middle value is <I>unselected</I> or <I>not selected</I>. You can <I>deselect</I> a check box by clicking it a second time. Click the Pears check box to deselect that check box. The X leaves the check box when you deselect the box.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>You can click not only on the box but anywhere within a text box's description. Therefore, to select or deselect the Pears check box, you can click the mouse cursor over the box next to Pears or click on the word Pears.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>There is also a way to select check boxes without the mouse. The user can press the Tab key until the check box description highlights. To select it, the user presses the Spacebar.<BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>Check boxes give your users multiple-choice access to choices that they need to make. Users select and deselect check boxes with the mouse or keyboard. Once the user selects all the check boxes needed, a command button keypress can signal to the running application that the user is finished. Your program then can check which values the user selected.<BR><BR><A NAME="E68E27"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Option Buttons Limit the Choices</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>Unlike check boxes, option buttons give your users a list from which to choose, but they can select exactly one option out of the list.<BR><P>Often, the option button controls are known as <I>mutually-exclusive</I> controls. Unless you group sets of option buttons in <I>frames</I> (described later in this unit), the user can select one and only one option button at a time.<BR><P>Click the Next Control command button to see the CONTROLS.MAK option buttons on your screen like the ones shown in Figure 3.8. Initially, no options are selected.<BR><P><B> <A HREF="03vel08.gif">Figure 3.8. Option buttons work almost like </B><B>mutually-exclusive check boxes.</A></B><BR><P>With the mouse, click one of the option buttons. Click another option button. At once, Visual Basic deselects the first option button and selects the one you just clicked. Select another option button to change the selected option once again. As you can see, Visual Basic ensures that you can select only one option at a time. Instead of check boxes, which permit multiple selections, you would display option buttons for the user whenever he can make only one choice out of several.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>Think ahead when you use option buttons. For example, you can select an initial option button for the user, through code or through the Properties window, when you write the program. By selecting an initial option button, you ensure that the user knows the best choice in a given situation, assuming there is a good default value that you can select.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>The option buttons work like check box controls except that, whereas the check box controls permit multiple selections, the user can select at most one option button at a time.<BR><P><B>You've Been Framed</B><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>The frame control enables you to group items together on a form. The group works almost like a miniform within the form.<BR><P>Although the user can select only one option button at a time, you can set up groups of option buttons on the same form. The user can then select one option button at a time from <I>within each frame</I>.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><I>Definition: </I>A <I>frame</I> is a box in which you can place control groups.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>You must always enclose the group within a frame by using the frame control. If you press the Next Control button again, you will see a frame appear in the middle of the form, as shown in Figure 3.9. You can place any controls in a frame, not just option buttons as in the figure.<BR><P><B> <A HREF="03vel09.gif">Figure 3.9. A frame with a command button and two </B><B>option button controls.</A></B><BR><P>If three frames of option button groups appeared on the form, you could select a maximum of three option buttons on the form—one in each framed set.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>To keep things simple at this point, only one control is discussed at a time. Only one set of option buttons currently appears on your form. There is no special reason to group them together except to show what a frame is.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>By framing objects together with the frame control, you can set up groups of controls that work together as if they were each on their own miniform within the larger Form window.<BR><BR><A NAME="E68E28"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Dropdown Combo Lists</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>A dropdown combo list is one of three kinds of lists that you can provide for your user. The dropdown list saves room on the screen by consuming only a single line on the form until the user opens the list to display the rest of the items in it.<BR><P>The combo box control actually turns into two different kinds of controls on the form, depending on how you set up the combo box. The two kinds of combo boxes are<BR><UL><LI> [lb] Dropdown combo boxes<BR><BR><LI> [lb] Simple combo boxes<BR><BR></UL><P>Press Next Control to see the combo dropdown box on the screen. As so often is the case, a command button appears next to the combo dropdown box. (See how you can resize every control, including command buttons, so that the controls consume exactly as much screen space as needed?)<BR><P>A list of items is stored in this dropdown combo box. To see the list, click the down arrow at the right of the empty dropdown combo box. You will see the list of electronic gear shown in Figure 3.10. Click the down arrow again. The list folds back up leaving the screen clear of the extra clutter.<BR><P><B> <A HREF="03vel10.gif">Figure 3.10. After opening the dropdown combo box </B><B>control.</A></B><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>When screen real estate space is precious, use a dropdown combo box control when you must offer a list of items to the user. The user can display the list when he needs to see what is in the list, and he can restore the list to its normal state when he is finished.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>The blank space at the top of the list is for the user to add additional items to the dropdown combo box. You will want to add a command
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?