通过Excel加载菜单栏

Platfor:Win7

Compiler:VS2010

使用第三方控件:Component One


新建一个窗体,在窗体上拖两个控件:

C1MainMenu和c1CommandDock

拖好控件后,通过代码将,设计的菜单和工具栏,通过execel导入

读取exel,导入到菜单代码如下:

    Private Sub CreateMenuToolbarXLS(Optional ByVal bLanguage As Boolean = False)
        On Error GoTo errhandle
        C1MainMenu1.VisualStyle = C1.Win.C1Command.VisualStyle.OfficeXP
        C1CommandDock1.DockingStyle = C1MainMenu1.VisualStyle
        'DockTabLeft.VisualStyle = MainMenu.VisualStyle
        CMD.SmoothImages = True

        C1CommandDock1.Dock = DockStyle.Top

        Dim MCA(340) As C1Command
        Dim MMU(50) As C1CommandMenu

        Dim MTB(7) As C1ToolBar
        Dim MCL(340) As C1CommandLink
        Dim iRow As Integer
        Dim i1 As Integer, i2 As Integer, i3 As Integer
        Dim it1 As Integer, it2 As Integer, it3 As Integer, it4 As Integer, it9 As Integer, it10 As Integer
        Dim sC As String, sE As String, sShortCut() As String, SICOIDString As String
        Dim sLanguage As String, iShortCut As Integer
        Dim Grid1 As New C1FlexGridClassic
        Grid1.LoadExcel("menu.xls")
        Grid1.Rows = Grid1.Rows + 1
        iRow = 2

        With Grid1
            Do Until .get_TextMatrix(iRow, CMDNO) = ""
                it1 = Val(.get_TextMatrix(iRow, CMDNO))  '命令编号
                it2 = Val(.get_TextMatrix(iRow, IsTopMenu)) ' 主菜单编号
                it3 = Val(.get_TextMatrix(iRow, IsMenu)) '菜单编号
                it4 = Val(.get_TextMatrix(iRow, IsParentMenu)) '父菜单编号
                sE = .get_TextMatrix(iRow, EnglistString)
                sC = .get_TextMatrix(iRow, ChineseString)
                it9 = Val(.get_TextMatrix(iRow, ParentToolbar))
                it10 = Val(.get_TextMatrix(iRow, TopToolbar))

                sLanguage = ""
                If bLanguage = False Then sLanguage = sC
                If bLanguage = True Then sLanguage = sE

                sShortCut = Nothing : i2 = -1
                If .get_TextMatrix(iRow, ShortCutString) <> "" Then
                    sShortCut = Split(.get_TextMatrix(iRow, ShortCutString), "+")
                    If sShortCut.GetLength(0) > 0 Then i2 = sShortCut.GetLength(0) - 1
                End If
                iShortCut = 0
                For i1 = 0 To i2
                    If sShortCut(i1) = "Ctrl" Then sShortCut(i1) = "Control"
                    i3 = Parse(GetType(Keys), sShortCut(i1))
                    iShortCut = iShortCut Or i3
                Next

                SICOIDString = .get_TextMatrix(iRow, ICOIDString)
                If it2 > 0 Then   '一级菜单
                    MMU(it2) = New C1CommandMenu
                    MMU(it2).Text = sLanguage
                    C1MainMenu1.CommandLinks.Add(New C1CommandLink(MMU(it2)))
                ElseIf it3 > 0 Then '二级菜单
                    MMU(it3) = New C1CommandMenu
                    MMU(it3).Text = sLanguage
                    MMU(it4).CommandLinks.Add(New C1CommandLink(MMU(it3)))
                Else
                    MCA(it1) = CMD.CreateCommand()
                    MCA(it1).Text = sLanguage
                    MCA(it1).Category = sLanguage
                    MCA(it1).Shortcut = iShortCut
                    '  MCA(it1).ShortcutText = .get_TextMatrix(.Row, ShortCutString)
                    If SICOIDString <> "" Then MCA(it1).Image = GetImage(SICOIDString)
                    MMU(it4).CommandLinks.Add(New C1CommandLink(MCA(it1)))
                    AddHandler MCA(it1).Click, AddressOf Menu_Click
                End If

                If it10 > 0 Then

                    MTB(it10) = New C1ToolBar
                    MTB(it10).CommandHolder = CMD
                    MTB(it10).Text = sLanguage
                    MTB(it10).VisualStyle = C1MainMenu1.VisualStyle
                    MTB(it10).CustomizeButton = True
                    C1CommandDock1.Controls.Add(MTB(it10))
                    MTB(it10).Dock = DockStyle.Left
                ElseIf it9 > 0 Then
                    MCL(it1) = New C1CommandLink(MCA(it1))
                    MCL(it1).ButtonLook = ButtonLookFlags.Image
                    MTB(it9).CommandLinks.Add(MCL(it1))
                End If
                iRow = iRow + 1
            Loop
            C1CommandDock1.Visible = True
        End With

        Grid1 = Nothing
        Exit Sub
errhandle:
        MsgBox(Err.Description)
        Grid1 = Nothing
    End Sub

    ' 菜单单击事件
    Public Sub Menu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        CMD_Click(CType(sender, C1Command).Text)
    End Sub

    ' 菜单单击响应操作
    Public Sub CMD_Click(ByVal CMDString As String)
        Select Case CMDString
            Case "a"

            Case "b"

            Case "c"

        End Select
    End Sub
做出来以后的效果,如下图:

希望对您有帮助

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值