vel11.htm

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

HTM
2,549
字号
<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>To remind yourself how the list box control works, you may want to load and run the CONTROLS.MAK project once again and scroll through the values in the list box control in the application.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Table 11.1 contains the list of property values that you can set for list box controls. You've seen many of the properties before because several controls share many of the same properties.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 11.1. The list 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>BackColor</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>The background color of the list box. It's a hexadecimal number representing one of thousands of possible Windows color values. You can 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>Columns</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>If 0 (the default), the list box scrolls vertically in a single column. If 1 or more, the list box items appear in the number of columns specified (one or more columns) which the user scrolls the list box horizontally to see all the items if needed. Figure 11.4 shows two identical list boxes, one with a Columns property of 0 and one with a Columns property of 3.</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 list box control around on the form. (You'll only rarely allow the user to move a list box control, 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 list box control 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 list box control 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 list values are 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 list values are 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 list box's text 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 list box values.</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 list values are 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 list box values are 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 color of the values inside the list box.</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 list box control.</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 list box control is part of a control array, the Index property provides the numeric subscript for each particular list box control (see the next unit).</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 list box control.</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 list box control. 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>MultiSelect</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>If 0-None (the default), the user can select only one list box item. If 1-Simple, the user can select more than one item by clicking with the mouse or by pressing the spacebar over items in the list. If 2-Extended, the user can select multiple items using Shift+click and Shift+arrow to extend the selection from a previously selected item to the current item. Ctrl+click either selects or deselects an item from the list.</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 List1, List2, and so on as you add subsequent list box controls to the form.</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Sorted</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>If True, Visual Basic doesn't display the list box values sorted numerically or alphabetically. If False (the default), the values appear in the same order in which the program added them to the list.</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 list box. If False, the list 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 list box control.</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 list 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 or False, indicating whether or not the user can see (and, therefore, use) the list 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 list box control consumes.</FONT></TABLE><P><B> <A HREF="11vel04.gif">Figure 11.4. Two identical list boxes with different </B><B>Columns</B><B> property settings.</A></B><BR><P>When placing a list box control on the form, decide how tall you want the list box to be by resizing the control to the size that fits the form best. Remember that if all the list box values don't all fit within the list box, Visual Basic adds scroll bars to the list box so that the user can scroll through the values.<BR><P>Table 11.2 contains all the list box events that you can program. Table 11.2 contains all the list box events that you can use in a program. You'll rarely write event procedures for list box controls, however. Most of the time, you'll let the user scroll through the list box values to see information they need; programs don't need to respond to list box events as often as they need to respond to command buttons and text boxes.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 11.2. The list 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>Click</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the user clicks the list 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 list 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 list 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>GotFocus</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the list 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 list 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 list box</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>LostFocus</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the list box loses the focus to another object</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>MouseDown</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the user presses a mouse button over the list box</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>MouseMove</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the user moves the mouse over the list box</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>MouseUp</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the user releases a mouse button over the list box</FONT></TABLE><P>Table 11.3 contains a list of list box control methods that you'll need to use for initializing, analyzing, and removing items from a list box control. Methods works like miniature programs that operate on controls. Here is the format of a method's use on a list box named lstItems:<BR><BR><PRE><FONT COLOR="#000080">lstItems.AddItem &quot;Arizona&quot;</FONT></PRE><P>The control name always precedes the method and the dot operator. Any data needed by the method appears to the right of the method.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 11.3. List box methods.</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>Method Name</I></FONT>

⌨️ 快捷键说明

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