Lecture 6: Creating Menus (Cont)
Introduction
In Lecture 5 , we discussed the MenuStrip Control, which:
Allows you to add Menus, Menu Items, and SubMenu Items…
We also used the Menu Editor :
Including the addition of Access Keys and Shortcut Keys As well as Check Marks Which allowed us to Add, Change, and Delete Menu Items.
In this lecture, we continue our discussion of Menus, by :
Finishing our QuickMenu Project
Coding the Main (but not the Formatting) ToolStrip Testing our MenuStrip’s Functions
Discussing Context Menus:
A second type of ‘drop-down’ menu also supported by VB .NET
Coding the Main ToolStrip
Testing the Menu’s Functions
Context Menus
When you point at TextBox1 and …
You will notice that a drop-down menu pops up automatically:
This Context Menu provides many of the behaviors we just coded…
However, we did not code this menu Furthermore, the Event Handlers we coded are not used here…
Instead this default Context Menu is provided automatically by Windows:
Whenever we on a Control or Window. These support default, customized management of the selected Control
For TextBoxes: Undo, Cut, Copy, Paste, Delete, etc.
VB .NET provides a method to Override such default menus:
Allowing you to restrict functionality (e.g., no copying operation).
The ContextMenuStrip Control
VB .NET provides a ContextMenuStrip Control for Developers
As usual, it can be placed on your Form directly…
The ContextMenuStrip is quite similar to the MenuStrip Control…
By being dragged from the ToolBox. It can be set up and customized in just the same way. However, it supports only 1 Top-level Menu.
Most Controls in the ToolBox have a ContextMenu Property
This allows you to define a ContextMenuStrip for use with that Control.
When you click the Property, you may select your own ContextMenu…
Rather than the Default.
Note: some Controls do NOT have a default ContextMenu
These are generally Controls that contain a List of Items (not just one item).
e.g.: ComboBoxes, ListBoxes
However, they still have a ContextMenu Property that can be set.
ContextMenu Example (1)
To demonstrate, let’s add a ContextMenuStrip to our Project:
We will code it to duplicate some convenient functions of our MenuStrip.
ContextMenu Example (2)
ContextMenu Ex (3)
ContextMenu Example (4)