VB.Net - StripMenuItem Control

The ToolStripMenuItem class supports the menus and menu items in a menu system. You handle these menu items through the click events in a menu system.
The following are some of the commonly used properties of the ToolStripMenuItem control −
Checked
Gets or sets a value indicating whether the ToolStripMenuItem is checked.
CheckOnClick
Gets or sets a value indicating whether the ToolStripMenuItem should automatically appear checked and unchecked when clicked.
CheckState
Gets or sets a value indicating whether a ToolStripMenuItem is in the checked, unchecked, or indeterminate state.
Enabled
Gets or sets a value indicating whether the control is enabled.
IsMdiWindowListEntry
Gets a value indicating whether the ToolStripMenuItem appears on a multiple document interface (MDI) window list.
ShortcutKeyDisplayString
Gets or sets the shortcut key text.
ShortcutKeys
Gets or sets the shortcut keys associated with the ToolStripMenuItem.
ShowShortcutKeys
Gets or sets a value indicating whether the shortcut keys that are associated with the ToolStripMenuItem are displayed next to the ToolStripMenuItem.
The following are some of the commonly used events of the ToolStripMenuItem control −
CheckedChanged
Occurs when the value of the Checked property changes.
CheckStateChanged
Occurs when the value of the CheckState property changes.
In this example, let us continue with the example from the chapter 'VB.Net - MenuStrip control'. Let us −
Hide and display menu items.
Disable and enable menu items.
Set access keys for menu items
Set shortcut keys for menu items.
Hide and Display Menu Items
The Visible property of the ToolStripMenuItem class allows you to hide or show a menu item. Let us hide the Project Menu on the menu bar.
Add the following code snippet to the Form1_Load event −
Add the following code snippet to the Form1_Load event −
Private Sub Form1_Load(sender As Object, e As EventArgs) _
Handles MyBase.Load
   ' Hide the project menu
   ProjectToolStripMenuItem1.Visible = False
   ' Set the caption bar text of the form.
   Me.Text = "tutorialspoint.com"
End Sub
Add a button control on the form with text 'Show Project'.
Add a button control on the form with text 'Show Project'.
Add the following code snippet to the Button1_Click event −
Add the following code snippet to the Button1_Click event −
Private Sub Button1_Click(sender As Object, e As EventArgs) _
Handles Button1.Click
   ProjectToolStripMenuItem1.Visible = True
End Sub
When the above code is executed and run using Start button available at the Microsoft Visual Studio tool bar, it will show the following window:
Clicking on the Show Project button displays the project menu −
Disable and Enable Menu Items
The Enabled property allows you to disable or gray out a menu item. Let us disable the Project Menu on the menu bar.
Add the following code snippet to the Form1_Load event −
Add the following code snippet to the Form1_Load event −
Private Sub Form1_Load(sender As Object, e As EventArgs) _
Handles MyBase.Load
   ' Disable the project menu
   ProjectToolStripMenuItem1.Enabled = False
   ' Set the caption bar text of the form.
   Me.Text = "tutorialspoint.com"
End Sub
Add a button control on the form with text 'Enable Project'.
Add a button control on the form with text 'Enable Project'.
Add the following code snippet to the Button1_Click event −
Add the following code snippet to the Button1_Click event −
Private Sub Button1_Click(sender As Object, e As EventArgs) _
Handles Button1.Click
   ProjectToolStripMenuItem1.Enabled = True
End Sub
When the above code is executed and run using Start button available at the Microsoft Visual Studio tool bar, it will show the following window −
Clicking on the Enable Project button enables the project menu −
Set Access Keys for Menu Items
Setting access keys for a menu allows a user to select it from the keyboard by using the ALT key.
For example, if you want to set an access key ALT + F for the file menu, change its Text with an added & (ampersand) preceding the access key letter. In other words, you change the text property of the file menu to &File.
Set Shortcut Keys for Menu Items
When you set a shortcut key for a menu item, user can press the shortcut from the keyboard and it would result in occurrence of the Click event of the menu.
A shortcut key is set for a menu item using the ShortcutKeys property.  For example, to set a shortcut key CTRL + E, for the Edit menu −
Select the Edit menu item and select its ShortcutKeys property in the properties window.
Select the Edit menu item and select its ShortcutKeys property in the properties window.
Click the drop down button next to it.
Click the drop down button next to it.
Select Ctrl as Modifier and E as the key.
Select Ctrl as Modifier and E as the key.

    63 Lectures 
     4 hours 

 Frahaan Hussain

    103 Lectures 
     12 hours 

 Arnold Higuit

    60 Lectures 
     9.5 hours 

 Arnold Higuit

    97 Lectures 
     9 hours 

 Arnold Higuit
 Print
 Add Notes
 Bookmark this page