JavascriptProva

sabato 18 gennaio 2014

Aggiunta di diversi sottomenu a runtime.

Ecco costruito un altro pezzetto: l'aggiunta di menu e sottomenu a runtime.
    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        matrice(0) = "Tizio"
        matrice(1) = "Caio"
        matrice(2) = "Sempronio"
        aggiungiElementiAlMenu()
        AggiungiSottomenu()
    End Sub
    Sub aggiungiElementiAlMenu()
        For n = 0 To matrice.Length - 1
            Dim mn As New ToolStripMenuItem With {.Text = matrice(n)}

            Menu.Items.Add(mn)
        Next

    End Sub
    Sub AggiungiSottomenu()
        For Each elemento In Menu.Items
            If elemento.Text = "Sempronio" Then
                For n = 0 To matrice.Length - 1
                    Dim submenu As New ToolStripMenuItem With {.Text = matrice(n)}
                    elemento.DropDownItems.Add(submenu)
                Next
            End If
        Next
    End Sub
Ho isolato le varie funzioni per avere un programma più maneggevole. E' meglio fare sempre così.

Nessun commento:

Posta un commento