|
|
Title | Make the items in a menu behave as a radio button group in Visual Basic .NET |
Description | This example shows how to make the items in a menu behave as a radio button group in Visual Basic .NET. |
Keywords | option button, menu, menu items, radio button, Visual Basic .NET, VB.NET |
Categories | Controls |
|
|
This example makes the items in a menu behave like a radio button group so when you select one, it displays a check mark and the others don't.
The key is the CheckMenuItem function.
This function takes as parameters a menu and a menu item. It loops through the objects contained in the menu. If an object is a menu item (e.g. not a separator or something else), the code sets its Checked property appropriately.
|
|
' Uncheck all menu items in this menu except checked_item.
Private Sub CheckMenuItem(ByVal mnu As ToolStripMenuItem, _
ByVal checked_item As ToolStripMenuItem)
' Uncheck the menu items except checked_item.
For Each item As ToolStripItem In mnu.DropDownItems
If (TypeOf item Is ToolStripMenuItem) Then
Dim menu_item As ToolStripMenuItem = _
DirectCast(item, ToolStripMenuItem)
menu_item.Checked = (menu_item Is checked_item)
End If
Next item
End Sub
|
|
|
|
|
|