用于从SQL存储过程添加菜单栏项和子项的代码

时间:2019-06-01 13:45:09

标签: vb.net menu dropdown menustrip

我需要Vb.net代码才能从SQL数据库动态添加菜单项和子项,并且在从数据库加载之前如何为我不知道其名称的每个菜单编写单击事件代码?

1 个答案:

答案 0 :(得分:0)

谢谢,我使用以下代码进行处理:

Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load


    ' Dim MenuStrip1 As New MenuStrip
    Dim oMenu1 As New ToolStripMenuItem

    With MenuStrip1.Items.Add("Set As Next Track")
        .Tag = 1
        ' AddHandler .Click, AddressOf lvTracksContextMenu_Click
    End With

    With MenuStrip1.Items.Add("&Loop Track")
        .Tag = 2
        AddHandler .Click, AddressOf lvTracksContextMenu_Click
    End With


    With oMenu1
        oMenu1.Name = "QuickQueue SubMenu"
        oMenu1.Text = "QuickQueue"
        AddHandler .Click, AddressOf lvTracksContextMenu_Click

        With .DropDownItems.Add("Item 1")
            .Tag = 101
            AddHandler .Click, AddressOf lvTracksContextMenu_Click
        End With
        With .DropDownItems.Add("Item 2")
            .Tag = 102
            AddHandler .Click, AddressOf lvTracksContextMenu_Click
        End With
        With .DropDownItems.Add("Item 3")
            .Tag = 103
            AddHandler .Click, AddressOf lvTracksContextMenu_Click
        End With
    End With
    MenuStrip1.Items.Add(oMenu1)

    'oLVTracksMenu.Show(New System.Drawing.Point(e.X + Me.Left, e.Y + Me.Top))

End Sub

Sub lvTracksContextMenu_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    MessageBox.Show(CType(sender, ToolStripItem).Tag)
End Sub

结束班级