【问题标题】:VB Net: Enable menu/contextmenu items based on security levelVB Net:根据安全级别启用菜单/上下文菜单项
【发布时间】:2012-08-03 02:22:52
【问题描述】:

我有一个项目,其中包含根据安全级别启用/禁用的多个项目。我正在尝试遍历表单上的所有控件以获取它们的名称并生成一个列表。我可以获得控件及其子项的所有名称,但它没有找到我拥有的所有上下文菜单。在设计期间,我将所有安全项目命名为 Sec_???。这是我到目前为止的代码。它将找到控件的名称并将其添加到列表中。如果它是绑定导航器,它将搜索菜单项并添加任何具有 Sec 标记的菜单项。如何对所有上下文菜单执行相同的操作?

Public Sub ProcessControls(ByVal ctrlContainer As Control)
    For Each ctrl As Control In ctrlContainer.Controls
        If ctrl.Name.ToString.StartsWith("Sec") Then
            FileOpen(1, "Sec_names.txt", OpenMode.Append)
            PrintLine(1, "**********")
            PrintLine(1, ctrl.Name.ToString & "," & ctrl.GetType.ToString)
            FileClose(1)
        End If
        If TypeOf ctrl Is BindingNavigator AndAlso ctrl.Name.ToString.StartsWith("Sec") Then
            Dim mnuName As BindingNavigator = CType(ctrl, BindingNavigator)
            For i = 0 To mnuName.Items.Count - 1
                Try
                    Dim mnu As ToolStripButton = CType(mnuName.Items(i), ToolStripButton)
                    If mnu.Name.ToString.StartsWith("Sec") Then
                        FileOpen(1, "Sec_names.txt", OpenMode.Append)
                        PrintLine(1, mnu.Name.ToString & "," & mnu.GetType.ToString)
                        FileClose(1)
                    End If
                Catch ex As Exception

                End Try
            Next
        End If
        ' recursively call this function for the control's children
        If ctrl.HasChildren Then
            ProcessControls(ctrl)
        End If
    Next
End Sub

编辑:ProcessControls(Me) 是我用来启动进程的。

【问题讨论】:

    标签: vb.net security contextmenu


    【解决方案1】:

    尝试使用

    For Each vComponent In Me.components.Components
        'Determine if it is component you want process
        'do something with it
    Next
    

    确保它不为空..Why is Me.Components Nothing?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-21
      • 1970-01-01
      • 2021-12-20
      相关资源
      最近更新 更多