以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  求助个问题,关于系统菜单目录循环  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=40769)

--  作者:kllm868
--  发布时间:2013/9/28 22:43:00
--  求助个问题,关于系统菜单目录循环

For Each a1 As RibbonMenu.Tab In RibbonTabs
    For Each a2 As RibbonMenu.group In a1.Groups
        For Each a3 As  RibbonMenu.RibbonItem  In  a2.Items
            If Typeof a3 Is RibbonMenu.Button

                Output.Show(a3.Text)  这里用a3.name 是没有问题的 但是我想显示出来标题,提示出错,怎么办

            End If
        Next
    Next
Next

以下内容为程序代码:

1 For Each a1 As RibbonMenu.Tab In RibbonTabs
2 For Each a2 As RibbonMenu.group In a1.Groups
3 For Each a3 As RibbonMenu.RibbonItem In a2.Items
4 If Typeof a3 Is RibbonMenu.Button
5
6 Output.Show(a3.Text) 这里用a3.name 是没有问题的 但是我想显示出来标题,提示出错,怎么办
7
8 End If
9 Next
10 Next
11 Next
12
13
14

错误图片


--  作者:有点甜
--  发布时间:2013/9/28 22:50:00
--  
 代码改成如下


For Each a1 As RibbonMenu.Tab In RibbonTabs
    For Each a2 As RibbonMenu.group In a1.Groups
        For Each a3 As  RibbonMenu.RibbonItem  In  a2.Items
            If Typeof a3 Is RibbonMenu.Button
                Dim o As RibbonMenu.Button = a3
                Output.Show(o.text)  \'这里用a3.name 是没有问题的 但是我想显示出来标题,提示出错,怎么办
            End If
        Next
    Next
Next

--  作者:kllm868
--  发布时间:2013/9/28 22:52:00
--  

说说原理呗 多谢了

 


--  作者:有点甜
--  发布时间:2013/9/28 22:54:00
--  
 RibbonItem  没有 text 属性,但是button 有,必须转换一下。
--  作者:kllm868
--  发布时间:2013/9/28 23:02:00
--  

哦哦 多谢,

 

那么多类型菜单 我怎么区别出来啊


--  作者:lsy
--  发布时间:2013/9/29 7:26:00
--  

下面是做权限表的时候,用到的,楼主可以参考:

 

DataTables("权限表").DataRows.Clear()

\'\'\'--------------功能区菜单
For Each rtb As RibbonMenu.Tab In RibbonTabs
    For Each grp As RibbonMenu.Group In rtb.Groups
        For Each itm As RibbonMenu.RibbonItem In grp.Items
            Dim dr As DataRow = DataTables("权限表").AddNew()
            dr("表窗口功能区") = rtb.Name
            dr("列控件功能组") = grp.Name
            dr("菜单按钮") = itm.Name
            If Typeof itm Is RibbonMenu.ToolBar OrElse Typeof itm Is RibbonMenu.ComboBox _
                OrElse Typeof itm Is RibbonMenu.FontComboBox OrElse Typeof itm Is RibbonMenu.MenuButton _
                OrElse Typeof itm Is RibbonMenu.SplitButton OrElse Typeof itm Is RibbonMenu.ToggleGroup Then
                For Each itm1 As RibbonMenu.RibbonItem In RibbonTabs(rtb.Name)(grp.Name)(itm.Name).Items
                    Dim dr1 As DataRow = DataTables("权限表").AddNew()
                    dr1("表窗口功能区") = rtb.Name
                    dr1("列控件功能组") = grp.Name
                    dr1("菜单按钮") = itm.Name
                    dr1("标准按钮") = itm1.Name
                    If Typeof itm1 Is RibbonMenu.ToolBar OrElse Typeof itm1 Is RibbonMenu.ComboBox _
                        OrElse Typeof itm1 Is RibbonMenu.FontComboBox OrElse Typeof itm1 Is RibbonMenu.MenuButton _
                        OrElse Typeof itm1 Is RibbonMenu.SplitButton OrElse Typeof itm1 Is RibbonMenu.ToggleGroup Then
                        For Each itm2 As RibbonMenu.RibbonItem In RibbonTabs(rtb.Name)(grp.Name)(itm.Name)(itm1.Name).Items
                            Dim dr2 As DataRow = DataTables("权限表").AddNew()
                            dr2("表窗口功能区") = rtb.Name
                            dr2("列控件功能组") = grp.Name
                            dr2("菜单按钮") = itm.Name
                            dr2("标准按钮") = itm1.Name
                            dr2("末级按钮") = itm2.Name
                        Next
                    End If
                Next
            End If
        Next
    Next
Next

\'\'\'----------------程序菜单左
For Each itm As RibbonMenu.RibbonItem In ApplicationMenu.LeftItems
    Dim dr As DataRow = DataTables("权限表").AddNew()
    dr("表窗口功能区") = "ApplicationMenu"
    dr("列控件功能组") = "LeftItems"
    dr("菜单按钮") = itm.Name
Next

\'\'\'----------------程序菜单右

For Each itm As RibbonMenu.RibbonItem In ApplicationMenu.RightItems
    Dim dr As DataRow = DataTables("权限表").AddNew()
    dr("表窗口功能区") = "ApplicationMenu"
    dr("列控件功能组") = "RightItems"
    dr("菜单按钮") = itm.Name
Next

\'\'\'----------------程序菜单底

For Each itm As RibbonMenu.RibbonItem In ApplicationMenu.BottomItems
    Dim dr As DataRow = DataTables("权限表").AddNew()
    dr("表窗口功能区") = "ApplicationMenu"
    dr("列控件功能组") = "BottomItems"
    dr("菜单按钮") = itm.Name
Next

\'\'\'----------------快速访问栏

For Each itm As RibbonMenu.RibbonItem In QAT.Items
    Dim dr As DataRow = DataTables("权限表").AddNew()
    dr("表窗口功能区") = "快速访问栏"
    dr("列控件功能组") = "快速访问栏"
    dr("菜单按钮") = itm.Name
Next

\'\'\'----------------配置栏

For Each itm As RibbonMenu.RibbonItem In ConfigBar.Items
    Dim dr As DataRow = DataTables("权限表").AddNew()
    dr("表窗口功能区") = "配置栏"
    dr("列控件功能组") = "配置栏"
    dr("菜单按钮") = itm.Name
Next

\'\'\'----------------快捷菜单
For Each conmenu As RibbonMenu.ContextMenu In ContextMenus
    For Each cmd As RibbonMenu.ContextCommand In conmenu.Items
        Dim dr As DataRow = DataTables("权限表").AddNew()
        dr("表窗口功能区") = "快捷菜单"
        dr("列控件功能组") = conmenu.Name
        dr("菜单按钮") = cmd.Name
    Next
Next


--  作者:狐狸爸爸
--  发布时间:2013/9/29 10:33:00
--  
以下是引用kllm868在2013-9-28 22:52:00的发言:

说说原理呗 多谢了

 

 

 

原理在这里有讲述:

 

http://www.foxtable.com/help/topics/1926.htm