vel03.htm

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

HTM
1,384
字号
button next to the combo box, as in CONTROLS.MAK, so that the user can add new items after typing them. Add two additional items by following these steps:<BR><OL><LI>Type <B>Disc Player</B>.<BR><BR><LI>Click the Add button. The data-entry box where you typed the new value goes blank, but Visual Basic has added Disc Player to the list.<BR><BR><LI>Type <B>Amplifier</B> and click the Add button.<BR><BR><LI>Display the dropdown list by clicking the down arrow. Notice that Visual Basic has added the two new items to the bottom of the list.<BR><BR></OL><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>Later, you will learn how Visual Basic can keep the items sorted alphabetically&#151;you do not have to write any code to sort the items.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>The items remain in the dropdown combo box list until you quit the program. Throughout this book, you will learn ways to save the items in the list and to initialize the lists with values using code.<BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>The dropdown combo box control offers a handy way for the user to view and add items to a list. The dropdown combo box gives you the advantage of listing items for the user without taking up screen space that is needed for other things. Your user can display the entire list by clicking the down arrow.<BR><BR><A NAME="E68E29"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Simple Combo Box</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>The simple combo box control does exactly the same thing as the dropdown combo box except that the simple combo box is always displayed in its <I>dropdown</I> form. In other words, if screen space is not a problem, you might want to use a simple combo box to display and collect values by using a list that does not require the user's extra keypress to open the list.<BR><P>Press the Next Control command button to see what a simple combo box looks like. As you can see, there is no difference between a simple combo box and a dropdown combo box except that the simple combo box is always open.<BR><P>If the simple combo box is not deep enough to display all the items in the list, Visual Basic adds a vertical scroll bar to the list so that the user can scroll through the list and view the items. As with the dropdown combo box, the user can add items to the simple combo box by typing the new value and clicking a command button that you set up.<BR><P>Type the value <B>Rugby</B> and click the Add command button. Scroll to the bottom of the list&#151;you can use the Page Down key to scroll&#151;to see the new sport's name.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>There is a third kind of combo box, called a <I>dropdown list box</I> control, that I will not cover here. The dropdown list box offers nothing new that you cannot get by using the other combo boxes or list box controls. Discussing it would only add confusion at this point.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>Simple combo box controls provide an easier way to display and collect list values. The user does not have to understand how to open a simple box control&#151;it is always open.<BR><BR><A NAME="E68E30"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>The List Box for Selections</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>List boxes are easy to understand compared to the two combo box controls. If you want users to select from a choice of options that you have supplied and you want to prevent them from adding additional items to the list, use list boxes.<BR><P>Figure 3.11 shows how your screen looks after you click the Next Control command button again. Later you will learn how to capture the item or items that the user selects from a list box.<BR><P><B> <A HREF="03vel11.gif">Figure 3.11. Selecting from a list box.</A></B><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Warning: </B>Check boxes and option buttons give users a chance to select from options, but you should not use check boxes or option buttons when there are many options to choose from. The scrolling list box and combo box controls use screen space more efficiently.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Click over one of the list box items with the mouse. Visual Basic highlights the item. Through programming, you will know when users selects an item, and you can analyze what they select. Click another item to select another choice.<BR><P>If the application requires multiple selections, you can set up the list box for multiple selections. The list box control inside the CONTROL.MAK application permits multiple selections. Hold down the Ctrl, Alt, or Shift key and click one or two additional items. Notice that Visual Basic highlights all the items. You can control whether users can select only one or more than one item from a list box. As with combo box lists, you can request that Visual Basic sort the items in the list box alphabetically.<BR><P>If you want, you can step through all the controls again by clicking the Next Control command button. You have now seen all the controls offered by the CONTROLS.MAK application. Although you will learn about more controls later in this book, this unit has described the primary controls that all Visual Basic programmers should master. Be sure that you know all the names of the controls. Study Figure 3.1 so that you know where each control is located on the Toolbox window.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Warning: </B>Not every Windows program that you write will contain all these controls. As a matter of fact, <I>no</I> Windows program should contain all these controls. The program would be too busy and would require too many different kinds of responses from the user.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>List boxes are controls that give the users choices from which they can select. Your application is responsible for initializing list boxes with values. The user cannot add items to a list box.<BR><BR><A NAME="E68E31"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Homework</B></FONT></CENTER></H3><BR><BR><A NAME="E69E29"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>General Knowledge</B></FONT></CENTER></H4><BR><OL><LI>Before you can run a program from within the Visual Basic environment, what must you do?<BR><BR><LI>What kind of file holds the description for the entire application?<BR><BR><LI>What is the filename extension for project files?<BR><BR><LI>Where can you look to learn the contents of a project file?<BR><BR><LI>What are controls for?<BR><BR><LI>What window do you get controls from as you build applications?<BR><BR><LI>Why is it a good reason to add an Exit command button to applications?<BR><BR><LI>True or false: The user can change text in a label control.<BR><BR><LI>Which control is good to use when you need text from the user?<BR><BR><LI>What kinds of things can you do with text displayed in a label or text box control?<BR><BR><LI>How do text controls act like mini word processors?<BR><BR><LI>What is the control called that gives users access to push buttons?<BR><BR><LI>True or false: The user can select at most one check box from a list of check box controls.<BR><BR><LI>True or false: The user can select at most one option button from a list of option button controls.<BR><BR><LI>What happens if the user selects a check box a second time?<BR><BR><LI>What control enables you to add several groups of option buttons to a form?<BR><BR><LI>True or false: Users can add items to lists displayed in dropdown combo box controls.<BR><BR><LI>True or false: Users can add items to lists displayed in simple combo box controls.<BR><BR><LI>True or false: Users can add items to lists displayed in list boxes.<BR><BR><LI>True or false: Users can select more than one item in a list box.<BR><BR><LI>What serves as the user's application background, holding all the controls for the user to work with?<BR><BR><LI>True or false: Visual Basic gives you, the programmer, a chance to add list box and combo box controls that display lists alphabetically.<BR><BR><LI>Name at least two ways in which the user can trigger a command button press.<BR><BR><LI>Why is a command button often next to a combo box control?<BR><BR></OL><BR><A NAME="E69E30"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>Find the Bug</B></FONT></CENTER></H4><BR><OL><LI>Pamela is writing a Visual Basic application that displays customer order information. Because of the large amount of information for each customer, Pamela finds that the screen is getting far too crowded. Pamela adds the list of goods that the customer bought to a simple combo box control. That way, the clerk can scroll through the list of items, and purchases are added to the list they are rung up. The simple combo box control takes up too much screen space. What recommendation would you give Pamela?<BR><BR></OL><BR><A NAME="E69E31"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>Extra Credit</B></FONT></CENTER></H4><BR><P>Suppose that you are writing an application that offers users a list of three values from which they can select at most one of the values. Which control is the most appropriate?<BR><P ALIGN=LEFT><A HREF="velp01.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="vel04.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 + -
显示快捷键?