vel19.htm
来自「简单的说明如何使用VB,非常适合初学使用者,而且是用图表来解说的」· HTM 代码 · 共 1,273 行 · 第 1/3 页
HTM
1,273 行
<HTML><HEAD><TITLE>Visual Basic in 12 Easy Lessons vel19.htm </TITLE><LINK REL="ToC" HREF="index.htm"><LINK REL="Index" HREF="htindex.htm"><LINK REL="Next" HREF="vel20.htm"><LINK REL="Previous" HREF="velp09.htm"></HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080"><A NAME="I0"></A><H2>Visual Basic in 12 Easy Lessons vel19.htm</H2><P ALIGN=LEFT><A HREF="velp09.htm" TARGET="_self"><IMG SRC="purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A><A HREF="index.htm" TARGET="_self"><IMG SRC="purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A><A HREF="vel20.htm" TARGET="_self"><IMG SRC="purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A><HR ALIGN=CENTER><P><UL><UL><UL><LI><A HREF="#E68E141" >What You'll Learn</A><LI><A HREF="#E68E142" >The Menu Design Window</A><LI><A HREF="#E68E143" >Adding the Menu Bar</A><LI><A HREF="#E68E144" >Adding Pull-Down Menus</A><LI><A HREF="#E68E145" >Connecting Menus to Event Procedures</A><LI><A HREF="#E68E146" > Add an Extra Touch to Help</A><LI><A HREF="#E68E147" >Homework</A><UL><LI><A HREF="#E69E131" >General Knowledge</A><LI><A HREF="#E69E132" >Find the Bug</A><LI><A HREF="#E69E133" >Write Code That...</A><LI><A HREF="#E69E134" >Extra Credit</A></UL></UL></UL></UL><HR ALIGN=CENTER><A NAME="E66E28"></A><H1 ALIGN=CENTER><CENTER><FONT SIZE=6 COLOR="#FF0000"><B>Lesson 10, Unit 19</B></FONT></CENTER></H1><BR><A NAME="E67E31"></A><H2 ALIGN=CENTER><CENTER><FONT SIZE=6 COLOR="#FF0000"><B>Menus Improve Usability</B></FONT></CENTER></H2><BR><BR><A NAME="E68E141"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>What You'll Learn</B></FONT></CENTER></H3><BR><UL><LI>The Menu Design window<BR><BR><LI>Adding the Menu Bar<BR><BR><LI>Adding pull-down menus<BR><BR><LI>Connecting menus to event procedures<BR><BR><LI>Adding an extra touch to Help<BR><BR></UL><P>This lesson explains how to add menus to your applications. Why add menus? As you already know, menus add commands to your application that the command buttons alone can't handle. Although a command button often performs the same task as one of the menu options, Windows users expect to see menus. Common program commands such as exiting a program reside on the menu's list of commands.<BR><P>How do you decide which menu options to include? Look at any popular Windows programs. Most Windows programs contain common menu commands and features. Visual Basic is one such program. Many of the Visual Basic pull-down menus contain the same commands as Microsoft Word and Microsoft Excel.<BR><P>Microsoft products aren't the only Windows programs with common menu items, either. When you write a program, you want users to feel comfortable with your interface. The user responds well to familiarity. Only when the interface contains common commands will the user be likely to use your program without fuss.<BR><BR><A NAME="E68E142"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>The Menu Design Window</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>Visual Basic makes creating and placing menu bar items into your application as easy as pushing command buttons and typing a few keystrokes. The Menu Design window contains menu description tools that enable you to create the application's menu bar, menu commands, and shortcut access keys to all of your applications.<BR><P>The Menu Design window is a dialog box that you access from the Form window by pressing Ctrl+M or by selecting Window Menu Design from Visual Basic's own menu bar. Figure 19.1 shows the Menu Design window and names the parts of the Menu Design window.<BR><P><B> <A HREF="19vel01.gif">Figure 19.1. The Menu Design window.</A></B><BR><P>The Menu Design window creates your menu, but you still need to write event procedures that tie menu command selections to actions taken by your application. When the user selects a menu command, Visual Basic generates an event, just as it generates an event when the user clicks a command button.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>Learning to add menus to your programs involves a mastery of the Menu Design window more than anything else. After you use the Menu Design window to create the menu, the menu's event procedures work just like the other event procedures that you've been writing throughout this book.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>As a prelude to adding a menu bar to your applications, study Figure 19.2 to learn the proper names for menu-related elements of a menu bar. This unit will walk you through the creation of a menu by adding a menu bar to the previous lesson's project application named PROJECT9.MAK.<BR><P><B> <A HREF="19vel02.gif">Figure 19.2. The parts of a menu.</A></B><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>This unit doesn't add event procedures to <I>every</I> menu command that you will add to PROJECT9.MAK. This unit explains how to create the menu and the menu's elements, and also explains how to hook up a couple of event procedures to the menu. Once you see how to create the menu and add an event procedure to a few menu commands, you know enough to add event procedures to all the rest.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>Add menus to your applications using the Menu Design window. The Menu Design menu enables you to add the menu bar, pull-down menu commands, separator bars, and shortcut access keystrokes to menu commands. After you create the menu, you'll write event procedures for each menu command. When the user selects a menu command, that menu command's event procedure will automatically execute.<BR><BR><A NAME="E68E143"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Adding the Menu Bar</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>An application's menu bar is one of the easiest parts of the menu system to add. This section walks you through the steps necessary to add a menu bar. Subsequent sections add pull-down menu items to each of the menu bar commands.<BR><P>The Menu Design window makes adding a menu bar to any application simple. Load the PROJECT9.MAK file now and get ready to add a menu bar that consists of the following commands:<BR><UL><LI>File<BR><BR><LI>Edit<BR><BR><LI>View<BR><BR><LI>Help<BR><BR></UL><P>Before doing anything else, save the PROJECT9.MAK form and project files under different names. By saving the files under different names, you'll protect the contents of the project so that the project matches the description given at the end of the previous lesson. Of course, if you <I>do</I> inadvertently change PROJECT9.MAK, you can always copy the files named PROJECT9.FRM and PROJECT9.MAK from this book's companion disks back to your hard disk.<BR><P>The following steps assume that you have the PROJECT9.MAK file loaded and that you want to save a copy of the form and project file under the names MYMENU.FRM and MYMENU.MAK.<BR><OL><LI>Select File, Save File As to open the Save File As dialog box and enter the new name, MYMENU.FRM, at the File Name prompt. Press Enter or click OK to close the dialog box. The File Save As dialog box saves only the form file.<BR><BR><LI>Select File, Save Project As to open the Save Project As dialog box and enter the new name, MYMENU.MAK, at the File Name prompt. Press Enter or click OK to close the dialog box.<BR><BR></OL><P>Now you have a copy of the PROJECT9.MAK project called MYMENU.MAK that you can modify by adding a menu. Lesson 9's project will remain intact.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>This book could go into a lot of detail explaining all the nuances of the Menu Design window. Luckily, you don't need all that preliminary detailed description. The Menu Design window is most easily mastered by jumping in and building a menu from scratch.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Every command on a menu bar, as well as the menu commands and separator bars that appear when you display a pull-down menu, has properties just as the other controls do. The Menu Design window acts like a dialog box that helps you set menu property values. The Property window is perfect for the other controls, but as you'll see, menus require a few extra kinds of property choices that the other controls don't need.<BR><P>With the MYMENU.MAK application still loaded, follow these steps to add the menu bar:<BR><OL><LI>Press Ctrl+M to open the Menu Design window. For this section of the unit, you're adding only the menu bar commands. Each menu bar command requires a caption (specified by the Caption property) and a name (specified by the Name property).<BR>Optionally, you can set other properties, such as an Enabled property, which determines whether the menu item is grayed out and unavailable for certain procedures, as well as a Visible property, which determines when the user can see the menu bar command. Generally, you'll rarely change these extra property values from their defaults for the menu bar commands.<BR><BR><LI>At the Caption prompt, type <B>&File</B>. The ampersand, as with the other controls' caption properties, indicates an access keystroke of Alt+F for the File menu item. As you type the caption, notice that Visual Basic adds the caption in the Menu Design window's lower section.<BR><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>The bottom half of the Menu Design window contains a description of the full menu, whereas the top half of the Menu Design window contains a description of individual items in the menu.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?