-
Adding Menu Items
I started on VB6 about 3 months ago and decided to transition to VB.Net instead. So... I am still trying to grasp basic concepts, so please be gentle.
Is it possible to prompt a user (with a form) and have their input added as a menu item?
Example: I want the user to input a hostname and then have it appear in the main forms menuitem.
Thanks..
-
Adding user input as a menu item is very easy, Consider you have an existing menu item (myParentMenuItem) that you want to add user input as a sub menu to it, calling 'AddAMenuItem' will add a sub menu with your specified text, See:
Private Sub MyMenuItemsHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
If (sender Is Nothing) = False Then
With CType(sender, System.Windows.Forms.MenuItem)
System.Windows.Forms.MessageBox.Show(.Text)
End With
End If
End Sub
Private Sub AddAMenuItem(ByVal itemText as String)
Dim tmpMenuItem As New System.Windows.Forms.MenuItem()
tmpMenuItem.Text = itemText
AddHandler tmpMenuItem.Click, AddressOf myMenuItemsHandler
Me.myParentMenuItem.MenuItems.Add(tmpMenuItem)
End Sub