|
|
|
double-click on the form |
|
|
in the right hand drop-down menu, select Resize |
Now we are
ready to add the menu.
To add a
menu, use Visual Basic's build-in Menu Editor. It can be found
under the Tools menu. (Note: the form must be active or
this item is not enabled.)

You will
now see the VB Menu Editor

Notice that
as you create new menu items, you must give them both a name
and a caption- just like any other object. All menu items begin
with the prefix mnu. As is traditional, the first main menu will
be the File menu. Type in the caption &File
and the name mnuFile and press OK. Run your project and
you will see the menu item, which, of course, does nothing yet! Now
we will add the rest of the file menu (we are "designing the interface"
here!) The first sub-menu under File is New. Go back to
the Menu Editor (Tools-Menu Editor) and add &New as a caption
and mnuNew as a name. Since New is a sub-menu, it must be "demoted"
a level. Clicking the right arrow at the middle left of the Menu Editor
does this. When correct, the Menu Editor looks like this:

You should
now be able to add the following sub-menus.
|
Caption |
Name |
|
&Open |
mnuOpen |
|
&Save |
mnuSave |
|
Save
&As |
mnuSaveAs |
Now we want
to add a separator bar to the menu. Windows uses these bars to visually
group menu items. To add a separator bar, give it the caption "-" (the
dash- no quotes) and a name (use mnuFileSep1).
|
Add a menu item for printing (caption: &Print, name: mnuPrint). |
|
|
Add another separator bar (caption: -, name: mnuFileSep2). |
|
|
Finally add the last of the File commands Exit, (caption:
&Exit, name: mnuExit). |

Now add
the other menu items. Don't forget to use the left and right arrows
in the Menu editor to "promote" and demote as necessary.
|
Caption |
Name |
|
&Edit |
mnuEdit |
|
Cu&t (Ctrl+X) |
mnuCut |
|
&Search |
mnuSearch |
|
&Help |
mnuHelp |
Now we are
ready to begin the serious work of coding!
![]()
First, lets provide messages for each menu item that indicates they are "in progress." Place a message box behind each menu item.
MsgBox "This feature is in progress",,"Message"
Now we can program the Exit button. Obviously, this is easy:
Unload Me
However, this is not how we expect a word processor to work, is it? When you choose "Exit" from a program, it seems to "know" weather you have saved your work or not. If you haven't, a message box should appear and ask if you would like to save your work before exiting. How can we accomplish this?
Suppose that we had a Boolean variable called Saved that is originally set to True (meaning that it is true that there is no work to be saved). It can be changed to False when something is typed in the text box. So--
In General Declarations
Private Saved As Integer 'Booleans are integers- 0 or 1
In Form_Load
Saved = True 'this is legal in VB
In txtWord_Change( )
Saved = False
In mnuEnd
if (Saved) Then
Unload Me
Else
'Save
End If
In mnuSave
reset Save to False
![]()
Similarly, the New command should do more than simply clear the screen.
txtWord.Text = ""
It should also check to see if the work has been saved and, if it has not, ask the user if they are sure they want to erase the work. Use a similar approach to Save to program this menu item.
![]()
Homework
Create the Word Processing .2 interface
Place messages behind each item to indicate "in progress"
Program New and Exit