' 如何判断快捷菜单的子菜单(写了六层,有需要,可以继续添加,用最笨的办法写的)
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编辑过]