Search In Site

25 June, 2013

Visual Basic : Adding A Menu To Form

What Item Goes In What Menu?
The Testing Department gives you a call to ask why the Paste item in your new application is in the View menu. You ask if they had a different menu in mind, and they mention something about the Edit menu. How can you avoid such calls? With the following lists. Users expect to find certain standard items in certain menus if your program is going to support those items. To start us off, here’s the kind of item you might find in the File menu (note that not all programs will use all these menus): 

" New
" Open
" Close
" Close All
" Save
" Save As
" Save All
" Properties
" Templates
" Page Setup
" Print Preview
" Print
" Print Using
" Send
" Update
" Exit

End statement, so this menu item is easy to implement). The Edit menu usually holds items like these:
" Undo

" Redo
" Cut
" Copy
" Paste
" Paste Using
" Paste Special
" Clear
" Select All
" Find
" Replace
" Bookmark
" Insert Object (unless you have a separate Insert menu)

The View menu has items like these:
" Toolbar
" Status Bar
" Refresh
" Options
The Window menu has items like these:
" New Window
" Cascade
" Tile Windows
" Arrange All
" Split
" List Of Windows
The Help menu has items like these:
" Help
" Help Index
" Help Table of Contents
" Search for Help On
" Web Support
" About

Adding A Menu To A Form
The design process is complete it’s time to start adding menus to your new program. But when you sit down and start looking for the Menu tool in the toolbox, you find that there isn’t one. Just how do you add a menu to a form? You use the Visual Basic Menu Editor. You’ll get a basic introduction to the Menu Editor here, and we’ll use it throughout this chapter. To add a menu to a form, select that form (that is, click on it), and open the Menu Editor by selecting the Menu Editor in the Tools menu. Or, you can select its icon in the toolbar (which has the tool tip _Menu Editor_).

Creating A New Menu
To create a new menu, you only have to provide two essential items: the caption of the menu and its name. The Caption property holds the title of the menu, such as File, and the Name property holds the name you’ll use for that menu in code, such as mnuFile. Fill in the Caption and Name properties for your new menu now. Congratulations you’ve created a new menu. Now it’s time to add items to the new menu.

Creating A New Menu Item
We can add a new menu item, say, New, to the File menu we’ve just created. To do so, click the Next button in the Menu Editor, moving the highlighted bar in the box at the bottom of the Menu Editor down one line. If you just entered new Caption and Name values and left it at that, you’d create a new menu, not a new menu item. So click the right-pointing arrow button in the Menu Editor now to indent the next item four spaces in the box at the bottom of the Menu Editor. Now enter the Caption (_New_) and Name, (_mnuFileNew_) values for the new menu item. The menu item you’ve just created appears in the Menu Editor below the File menu item and indented, like this:
File
....New

This means that we now have a File menu with one item in its New. That’s how your menu system is displayed in the Menu Editor: as a series of indented items. For example, here’s how a File menu with New and Open items, followed by an Edit menu with three items, Cut, Copy, and Paste, would look in the Menu Editor:
File
....New
...Open
Edit
....Cut
....Copy
....Paste

Here’s how to create a new menu system in the Menu Editor, step-by-step:
1. Enter the first menu’s Caption and Name.
2. Click the Next button (or press Enter).
3. Click the right arrow to indent one level, making this next entry a menu item.
4. Enter the menu item’s Caption and Name.
5. Click the Next button (or press Enter).
6. Repeat Steps 4 and 5 for all the items in the first menu.
7. Click the Next button (or press Enter).
8. Click the left arrow to outdent, making this next entry a menu.
9. Enter the next menu’s Caption and Name.
10. Click the right arrow to indent one level, making this next entry a menu item.
11. Repeat Steps 4 and 5 for the items in this new menu.
12. Repeat Steps 7 through 11 for the rest of the menus in the program.
13. Click on OK to close the Menu Editor.
14. Edit the code.

You edit the code for menu items just as you do for other control’s click the menu item in the form under design (opening the item’s menu if necessary). This opens the menu item’s event handler, like this:
Private Sub mnuFileNew_Click()
End Sub


Just add the code you want to execute when the user chooses this menu item to the event handler procedure:
Private Sub mnuFileNew_Click()
LoadNewDoc End Sub

0 comments:

Post a Comment

Dear Visitors All The Tricks And Hacks Posted Here Are Only For Knowledge Purpose.Don't Use These for Illegal Operations.

 
Twitter Bird Gadget