vb.net 用MenuStrip动态创建菜单,怎样添加子菜单,并增加click事件

前端之家收集整理的这篇文章主要介绍了vb.net 用MenuStrip动态创建菜单,怎样添加子菜单,并增加click事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
 Private Sub Form9_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load

        MenuStrip1.Items.Add("文件",Nothing,AddressOf menuItem_Click).Name = "mnuFile"
        MenuStrip1.Items.Add("编辑",AddressOf menuItem_Click).Name = "mnuEdit"

        Dim doItem As ToolStripMenuItem = MenuStrip1.Items("mnuFile")
        doItem.DropDownItems.Add("打开",AddressOf menuItem_Click).Name = "mnuOpen"
        doItem.DropDownItems.Add("保存",AddressOf menuItem_Click).Name = "mnuSave"

    End Sub

    Private Sub menuItem_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles MenuStrip1.Click

        Try
            Select Case sender.name
                Case "mnuFile"
                    MsgBox("文件")
                Case "mnuEdit"
                    MsgBox("编辑")
                Case "mnuOpen"
                    MsgBox("打开")
                Case "mnuSave"
                    MsgBox("保存")

            End Select

        Catch ex As Exception

        End Try

    End Sub

猜你在找的VB相关文章