vel11.htm
来自「简单的说明如何使用VB,非常适合初学使用者,而且是用图表来解说的」· HTM 代码 · 共 2,549 行 · 第 1/4 页
HTM
2,549 行
<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 combo box. If False, the combo box 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 combo box control.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Text</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The initial value only that the user sees in the combo box.</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 a combo box control to the top of the form.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Visible</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>True (the default) or False, indicating whether the user can see (and, therefore, use) the combo box control.</FONT><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 combo box control consumes.</FONT></TABLE><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>Notice that there is no MultiSelect combo box property as there is with list box controls. The user can select only one combo box item at any one time.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Table 11.5 contains a list of the combo box events for which you can write matching event procedures when your program must react to a user's manipulation of a combo box.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 11.5. The combo box control'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>Change</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the user changes the value in the data entry portion of the dropdown combo or the simple combo box; not available for dropdown list boxes because the user can't change data in them</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 combo box control</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 combo box control</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 of the combo box 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>DropDown</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the user opens a dropdown combo box or a dropdown list box</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>GotFocus</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the combo box 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 form; otherwise, the form 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 combo box</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 over the combo box</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>LostFocus</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the combo box loses the focus to another object</FONT></TABLE><P>The combo box controls support the same methods that the list box controls support. Therefore, you can add, remove, count, and select items from the combo box if you apply the methods seen in Table 11.3.<BR><P><FONT COLOR="#FF8000"><B><I>Stop and Type: </I></B></FONT>Listing 11.3 contains a command button's event procedure that adds a value to a combo box's list of items. Unlike text box controls, you'll need to provide the user with some data entry mechanism, such as a command button, that informs the program when to use the AddItem method to add an item to a combo box.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>Listing 11.3 assumes that another procedure, such as the Form_Load() procedure, added the initial values to the combo box.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>The three kinds of combo boxes offer three similar controls with which your program can interact by showing lists of values and, optionally, allowing the user to enter values in the lists. Two of the combo boxes are dropdown lists that don't consume form space until the user opens the combo boxes.<BR><P><FONT COLOR="#000080"><B>Listing 11.3. A command button's event procedure that adds an item to a combo box.</B></FONT><BR><PRE><FONT COLOR="#000080">1: Sub cmdSimple_Click ()2: ' Add the user's item to the simple combo3: comSCtrl.AddItem comSCtrl.Text4: comSCtrl.Text = ""5: comSCtrl.SetFocus6: End Sub</FONT></PRE><P><FONT COLOR="#FF8000"><B><I>Output: </I></B></FONT>Figure 11.8 contains a screen that you saw in the second lesson of the book. The CONTROLS.MAK application demonstrates the simple combo box and shows how you can set up an application to add items to a list of values.<BR><P><B> <A HREF="11vel08.gif">Figure 11.8. Adding data to a simple combo box control.</A></B><BR><P><FONT COLOR="#FF8000"><B><I>Analysis: </I></B></FONT>The command button in Figure 11.8 is named cmdSimple, so clicking the command button executes the event procedure shown in Listing 11.3. Line 3 stores the combo box's Text property value to that combo box's list of items. The combo box <I>will not</I> contain a user's entry in the upper data entry portion of the combo box until an AddItem method adds that entry to the list. The Text property always holds the current value shown in the data entry portion of the combo box, but the AddItem method must add that value to the list.<BR><P>As soon as the user's entry is added, line 4 erases the data entry portion of the combo box. After all, the user's text will now appear in the lower listing portion of the combo box (thanks to line 3), so line 4 clears the data entry area for more input. In addition, line 5 sets the focus back to the combo box (the focus appears in the data entry area that line 4 cleared) so that the user is ready to add an additional item to the combo box.<BR><BR><A NAME="E68E90"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Homework</B></FONT></CENTER></H3><BR><BR><A NAME="E69E78"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>General Knowledge</B></FONT></CENTER></H4><BR><OL><LI>How can arrays help you process large amounts of data?<BR><BR><LI>What is an array element?<BR><BR><LI>What is an array subscript?<BR><BR><LI>If an array contains 20 elements, how many names does the array have?<BR><BR><LI>If an array contains 20 elements, how many subscripts does the array have (assume that there is an Option Base 1 statement in the (general) procedure section of the Code window).<BR><BR><LI>True or false: Every element in an array must be the same data type.<BR><BR><LI>How can you differentiate between array elements?<BR><BR><LI>What statement defines arrays inside event procedures?<BR><BR><LI>Assuming that there is an Option Base 1 statement in the (general) procedure section of the Code window, what is the starting subscript for all arrays that you subsequently define in the program?<BR><BR><LI>Which loop works best for array processing?<BR><BR><LI>Which controls work like arrays?<BR><BR><LI>True or false: The user can enter new values in list boxes.<BR><BR><LI>True or false: The user can select more than one value in a list box.<BR><BR><LI>True or false: A list box may consist of more than one column.<BR><BR><LI>Why are methods important for list box and combo box controls?<BR><BR><LI>Which event procedure do programmers often use to initialize list and combo box controls?<BR><BR><LI>True or false: There are three kinds of combo boxes.<BR><BR><LI>True or false: There are three kinds of combo box controls on the toolbox.<BR><BR><LI>True or false: The list box methods work well for the combo boxes also.<BR><BR><LI>True or false: List and combo box controls have subscripts just as arrays have.<BR><BR><LI>What is the method that indicates whether a list box item is selected?<BR><BR><LI>True or false: A simple combo box can be opened with a user's click of the simple combo box's down arrow.<BR><BR></OL><BR><A NAME="E69E79"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>Write Code That...</B></FONT></CENTER></H4><BR><OL><LI>Paul wants to ensure that all items in his list box are sorted. Which property should Paul set to 1-Sorted?<BR><BR><LI>Suppose that you want to define an array of three high school student ages in a list. Write the Static statement that defines the ages.<BR><BR><LI>What list box property would you set to 1 or 2 if you wanted to allow the user to select from multiple list box items at one time?<BR><BR><LI>Mary wants to erase all list box items when the user clicks a special command button named cmdGoAway. Write the event procedure needed to erase the list box named lstVals if the user clicks the cmdGoAway command button.<BR><BR><LI>Why should you offer a command button for the user to use when adding items to a combo box control?<BR><BR></OL><P><B>Find the Bug</B><OL><LI>Carla needs to define a list box with 24 items in it. In the Form_Load() event procedure, Carla attempts this:<BR>Static lstData(24) ' Define 24 list boxes<BR>Tell Carla what she's doing incorrectly.<BR><BR></OL><BR><A NAME="E69E80"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>Extra Credit</B></FONT></CENTER></H4><BR><P>Write an application that asks the user, with an InputBox() function, whether he or she wants to see a dropdown combo box, a simple combo box, or a dropdown list box. Ask the user, in the InputBox() prompt string, to type a 1, 2, or 3 to indicate which of the three kinds of combo boxes are requested. Use a loop to check that the user enters a proper value, and if the user enters a value other than 1, 2, or 3, keep prompting until the user enters one of the three values. Then display a list of ten ice cream flavors in that particular combo box control. Hint: Assign the user's entry to the combo box's Style property.<BR><P ALIGN=LEFT><A HREF="velp05.htm" TARGET="_self"><IMG SRC="purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A><A HREF="#I0" TARGET="_self"><IMG SRC="purtop.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Page Top"></A><A HREF="index.htm" TARGET="_self"><IMG SRC="purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A><A HREF="vel12.htm" TARGET="_self"><IMG SRC="purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A><A </BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?