CONSTRUCAO DE MENUSTRIP DINAMICO

GGERMINIANI 25/07/2013 16:55:10
#426525
Boa tarde para todos.

Localizei o código abaixo na internet (de uma pessoa com dúvida) e possivelmente a solução desta respodta pode me ajudar numa necessidade... basta criar 5 itens no formulário:
btnAddMenuItem
btnAddMenu
txtMenu
txtMenuItem
cmbMenu

Citação:

Public Class Form1
Private mnuMain As MainMenu
Private mnuItem As MenuItem
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
[ô]Declare main menu
mnuMain = New MainMenu()
[ô]Add submenu with menu item
mnuItem = New MenuItem()
mnuItem.MenuItems.Add(New MenuItem([Ô][Ô]))
Me.Menu = mnuMain
[ô]Add event-handler to each MenuItems
For Each m As MenuItem In mnuItem.MenuItems
AddHandler m.Click, AddressOf HandleMenuItemClick
Next
End Sub
[ô]Event-handler to handle any and all MenuItem clicks
Private Sub HandleMenuItemClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
[ô]Throw exception if the sender is not a menu item
If (Not (TypeOf (sender) Is MenuItem)) Then
Throw New Exception([Ô]HandleMenuItemClick called incorrectly![Ô])
End If
[ô]Convert sender to menu item type
Dim s As MenuItem = CType(sender, MenuItem)
Select Case s.Text
[ô]Response will be a messagebox that displays the selected menu item[ô]s text
Case txtMenuItem.Text
MessageBox.Show(txtMenuItem.Text)
End Select
End Sub
Private Sub btnAddMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddMenu.Click
[ô]Check if text is entered into textbox
If txtMenu.Text = [Ô][Ô] Then
MessageBox.Show([Ô]Please enter text into textbox before pressing the add button[Ô])
txtMenu.Text = [Ô][Ô]
Return
ElseIf cmbMenu.Items.Contains(txtMenu.Text) Then
MessageBox.Show([Ô]Menu already added[Ô])
txtMenu.Text = [Ô][Ô]
Else
cmbMenu.Items.Add(txtMenu.Text)
mnuMain.MenuItems.Add(txtMenu.Text)
txtMenu.Text = [Ô][Ô]
End If
End Sub
Private Sub btnAddMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddMenuItem.Click
[ô]Checks if there is text in the textbox
If txtMenuItem.Text = [Ô][Ô] Then
[ô]Display a message to the user
MessageBox.Show([Ô]Please enter text into text box before pressing the add button[Ô])
txtMenuItem.Text = [Ô][Ô]
Return
ElseIf cmbMenu.Items.Contains(txtMenuItem) Then
MessageBox.Show([Ô]Item already exists in the dropdownlist[Ô])
txtMenuItem.Text = [Ô][Ô]
Else
[ô]?????
End If
End Sub
End Class



Há alguma maneira de incluir um subitem a partir do nome do item?

Grato,
Gustavo.
Faça seu login para responder