One of the basic components of most applications is a Menu of some description. Visual Basic.Net offers a simple system to allow menus to be developed - along the tool bar in the first instance, but with drop down a possibilty on each entry. However, code must be written for the Menu to do anything.
To create a menu, open your Ace Taxis project and ensure that the form is open and active.
To insert the strip menu activate the Toolbox, scroll down to Menus and Toolbars and select Menu Strip.
In this case the Menu Strip icon appears under the form, and on the top of the form you will see a small box saying "Type here".

When you click in the box to type, another box appears underneath, and one to the right. The one underneath is if you want a nested menu. If you do not click on these to add text they will disappear.
Having clicked in the first one type &File. Click in the one underneath this and type E&xit. Click on the right hand one and type &Clear.
These are two new objects therefore they have properties. Click anywhere on the form, then back onto &File. The properties of this button are shown - change the Name property to mnuFile. Change the name property to mnuExit & mnuClear for the other menu items.
Double click the &Clear button to open the code window and type in
lstDisplay.item.clear
Double click the E&xit button and type in the standard exit code (me.close())
Save your work and press F5 to test that the Clear and Exit menu items work.
We now need to address how the confirm to quit option will work. If the Ask Before Closing option is checked (default), then a message box will pop up with a quit Yes / No option.
Click in the menu space under E&xit and type in "Ask before Closing" (This now will give you 2 options under the File tab). In the properties box for this tab make the Name property mnuAskBeforeClosing. Scroll down to Checked property and set to True.
Firstly, we need to activate the option button (give it the ability to be checked or unchecked). Double click the Ask before Closing tab top open the code window and type in
'toggle AskBeforeClsoing on and off
If mnuAskBeforeClosing.Checked = True Then
mnuAskBeforeClosing.Checked = False
Else
mnuAskBeforeClosing.Checked = True
End If
The following code needs to be added BEFORE the me.close() code in the mnuExit code segment.
If mnuAskBeforeClosing.Checked Then
'the next 2 line needs to be pasted as one continuous line
If MessageBox.Show("Do you really want to exit?", "7 taxis", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = windows.forms.DialogResult.No Then
Exit Sub
End If
End If
Me.Close()
Message boxes can not only show a message but can be tested for a yes / no response as in this case. If "No" is selected then the Exit sub is executed and the code never reaches me.Close() so the project keeps running.
Author FDS with help from SAMS "Teach yourself VB.Net 2003 in 24 hours"
Last Modified 21/4/2007