以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  如何获取快捷菜单的子菜单  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=55591)

--  作者:9EQ98
--  发布时间:2014/8/19 17:24:00
--  如何获取快捷菜单的子菜单

\' 如何判断快捷菜单的子菜单(写了六层,有需要,可以继续添加,用最笨的办法写的)

 

Dim El_MU As RibbonMenu.ContextMenu
Dim EL_MN As String = "测试子菜单"  \'
For Each El_MU In ContextMenus
EL_MN = EL_MU.NAME
For Each M1 As object In ContextMenus(EL_MN).Items
    Dim P1 As System.Reflection.PropertyInfo = ContextMenus(EL_MN).Items(M1.name).Gettype().GetProperty("Items")
    If P1 IsNot Nothing Then
        output.show(M1.text & "-" & M1.name  & "  " & "有子菜单")
        For Each M2 As object In  ContextMenus(EL_MN).Items(M1.name).Items
            Dim P2 As System.Reflection.PropertyInfo = ContextMenus(EL_MN).Items(M1.name).Items(M2.name).Gettype().GetProperty("Items")
            If P2 IsNot Nothing Then
                output.show(M2.text & "-" & M2.name & "  " & "有二级子菜单")
                For Each M3 As object In ContextMenus(EL_MN).Items(M1.name).Items(M2.Name).Items
                    Dim P3 As System.Reflection.PropertyInfo = ContextMenus(EL_MN).Items(M1.name).Items(M2.name).Items(M3.Name).Gettype().GetProperty("Items")
                    If P3 IsNot Nothing Then
                        output.show(M3.text & "-" & M3.name & "  " & "有三级子菜单")
                        For Each M4 As object In ContextMenus(EL_MN).Items(M1.name).Items(M2.Name).Items(M3.Name).Items
                            Dim P4 As System.Reflection.PropertyInfo = ContextMenus(EL_MN).Items(M1.name).Items(M2.name).Items(M3.Name).Items(M4.Name).Gettype().GetProperty("Items")
                            If P4 IsNot Nothing Then
                                output.show(M4.text & "-" & M4.name & "  " & "有四级子菜单")
                                For Each M5 As object In ContextMenus(EL_MN).Items(M1.name).Items(M2.Name).Items(M3.Name).Items(M4.Name).Items
                                    Dim P5 As System.Reflection.PropertyInfo = ContextMenus(EL_MN).Items(M1.name).Items(M2.name).Items(M3.Name).Items(M4.Name).Items(M5.Name).Gettype().GetProperty("Items")
                                    If P5 IsNot Nothing Then
                                        output.show(M5.text & "-" & M5.name & "  " & "有五级子菜单")
                                        For Each M6 As object In ContextMenus(EL_MN).Items(M1.name).Items(M2.Name).Items(M3.Name).Items(M4.Name).Items(M5.Name).Items
                                            Dim P6 As System.Reflection.PropertyInfo = ContextMenus(EL_MN).Items(M1.name).Items(M2.name).Items(M3.Name).Items(M4.Name).Items(M5.Name).Items(M6.Name).Gettype().GetProperty("Items")
                                            If P6 IsNot Nothing Then
                                                output.show(M6.text & "-" & M6.name & "  " & "有六级子菜单")
                                                \'复制一层循环,在此加入后修改

                                            Else
                                                output.show(M6.text & "-" & M6.name)
                                            End If
                                        Next
                                    Else
                                        output.show(M5.text & "-" & M5.name)
                                    End If
                                Next
                            Else
                                output.show(M4.text & "-" & M4.name)
                            End If
                        Next
                       
                    Else
                        output.show(M3.text & "-" & M3.name)
                    End If
                Next
            Else
                output.show(M2.text & "-" & M2.name)
            End If
        Next
    Else
        output.show(M1.text & "-" & M1.name)
    End If
Next
Next

 

 

 

 

 

 

 


图片点击可在新窗口打开查看此主题相关图片如下:获取快捷菜单.jpg
图片点击可在新窗口打开查看
[此贴子已经被作者于2014-8-19 17:48:08编辑过]

--  作者:有点甜
--  发布时间:2014/8/19 17:26:00
--  

 写递归。

 

 参考例子 http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=49604&authorid=0&page=0&star=2

 


--  作者:Bin
--  发布时间:2014/8/19 17:30:00
--  
快捷菜单有特殊性,这个递归例子没有参考意义呢.
--  作者:9EQ98
--  发布时间:2014/8/19 17:49:00
--  
快捷菜单没办法写递归
--  作者:有点甜
--  发布时间:2014/8/19 17:54:00
--  

 可以写,肯定可以写。

 

 不过,你直接用循环的效率肯定比写递归要好得多。

 

 菜单递归例子

 

 http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=55466&skin=0