vel06.htm
来自「简单的说明如何使用VB,非常适合初学使用者,而且是用图表来解说的」· HTM 代码 · 共 2,468 行 · 第 1/4 页
HTM
2,468 行
<P><B> <A HREF="06vel06.gif">Figure 6.6. The user now knows what data is </B><B>expected.</A></B><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>Add access shortcut keystrokes to labels that describe data-entry text boxes.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Suppose that the user fills in the six sales figures. He might want to go back and change an entry to fix a typing error. When you put text boxes in an application, think about giving your users a chance to correct their mistakes by providing them an access keystroke to each text box.<BR><P>As you know, access shortcut keys are the Alt+Keystroke combinations that you can apply to controls such as command buttons. In Figure 6.6, the user can press Tab to the Exit command button, click the Exit command button with the mouse, or press Alt+X—the access shortcut key for the command button. The underline indicates which letter provides the access.<BR><P>Text box controls do not have captions, so you cannot directly add access keystrokes to text boxes. Nevertheless, you can add underlined access keystrokes to label captions. For example, suppose that you changed the first label in Figure 6.6 from January to January. The access keystroke for that label is Alt+J.<BR><P>But wait, there's a problem. Labels cannot receive the focus! If a label contains an access keystroke and the user presses that access keystroke combination, Visual Basic knows that the focus cannot go to the label. It sends the focus to the next control in the TabIndex sequence. All controls contain a TabIndex property. A different numeric value appears in each control's TabIndex property. As you learned in the previous unit, the TabIndex property determines the focus order. Suppose that you assigned a TabIndex value of 0 to the January label and a TabIndex value of 1 to the text box to the right of January. When the user presses Alt+J, the focus goes to the text box because the label cannot receive a focus.<BR><P>Therefore, after you place all the controls on a form and set their properties, go back to each control and make sure that each label contains a TabIndex value that is one less than the text box control that the label describes. Make sure, as well, that the overall TabIndex sequence is organized so that it sends the focus from control to control in the order you want as the user presses Tab. Figure 6.7 shows the six-month sales data-entry application in which each label has an access shortcut keystroke. The figure indicates the TabIndex value for each control. Given the TabIndex values, the focus goes directly to the May text box when the user presses Alt+Y.<BR><P><B> <A HREF="06vel07.gif">Figure 6.7. The </B><B>TabIndex</B><B> properties describe the </B><B>access keystroke order.</A></B><BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>Although you cannot add access keys to text boxes, you can add access keys to the labels that describe text boxes. By doing so, you give your users shortcut access to any text box on the form.<BR><BR><A NAME="E68E52"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Introducing Control Events</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>You know that when the user clicks command buttons and types text in text boxes, he triggers events that your program can capture. This section discusses the events available for the command button, label, and text box controls. Lesson 4 begins your study of the Visual Basic programming language, so you need to understand which events are possible as you write event procedures that respond to those events.<BR><P>Here's another section full of tables! Nevertheless, they show you all the events available for the controls you have been learning. In the next lesson, you will begin to write code. The code that you write usually appears inside event procedures. You need to know which events are available, so that you can write the correct event procedures. <BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>As you learn new controls in subsequent lessons, you will find more tables properties and events. Enjoy.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Table 6.3 describes the events related to forms. Perhaps the most important form event is Load, which triggers whenever the user runs an application. Throughout this book, you will use the Load event to put startup code in applications so that the startup code executes immediately after the user runs the application and immediately before the form appears on the screen.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>Remember that if you want to see what events are possible for a certain control, place the control on the Form window and double-click the control. Visual Basic opens a Code window. Open the Proc: dropdown combo box list to see a list of the events available for that control.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 6.3. Form 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>Activate</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when a form becomes the active window. In Visual Basic, the Activate event occurs after the Load event displays the form.</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 form with the mouse.</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 form with the mouse.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Deactivate</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when another form becomes the active window. Not available in the Visual Basic Primer Edition.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>DragDrop</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when a drag operation over the form 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 over the form.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>GotFocus</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the form 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 and the KeyPreview property for the controls on the form is set to True. Otherwise, the control 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 form.</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.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>LinkClose</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when a DDE operation terminates.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>LinkError</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when a DDE operation fails.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>LinkExecute</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when a DDE operation begins to execute.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>LinkOpen</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when a DDE operation begins.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Load</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the form loads and before it appears on the screen.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>LostFocus</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the form loses the focus.</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 the mouse button over the form.</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 form.</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 the mouse over the form.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Paint</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when Visual Basic must redraw a form because another object overwrote part of the form and then the user moved the object and exposed the hidden part of the form.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>QueryUnload</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs immediately before the application terminates.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Resize</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the user resizes the form.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Unload</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the form is unloaded using the Unload statement.</FONT></TABLE><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Warning: </B>Don't Table 6.3 scare you away from Visual Basic! You will use only a handful of these events in most of your programming work.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Notice that all the descriptions in Table 6.3 begin with the word <I>occurs</I>. Each of these table entries are events that occur as the result of a user or Windows action. Therefore, if you want to do something when the user clicks the form, you write code that performs the task that you want accomplished and you put that code inside the form's Click event procedure. If the form is named MyForm, the Click event procedure is named MyForm_Click(), as you learned in the <A HREF="vel04.htm">Unit 4</A>. You will start writing the code for event procedures in the next lesson.<BR><P>Table 6.4 describes the events available for the command button controls that you place on forms.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 6.4. Command button 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 command button with the mouse.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>DragDrop</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when a drag operation of the command button 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 of the command button.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>GotFocus</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the command button 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 and the KeyPreview property for any control on the form is set to False. 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 command button.</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.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>LostFocus</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Occurs when the command button loses the focus to another control or to the form.</FONT>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?