0

セキュリティレベルに基づいて有効/無効になっているいくつかのアイテムを含むプロジェクトがあります。フォーム上のすべてのコントロールを繰り返し処理して、名前を取得し、リストを生成しようとしています。コントロールとその子のすべての名前を取得できますが、すべてのコンテキスト メニューを見つけることができません。設計中に、すべてのセキュア項目に 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) は、プロセスを開始するために使用するものです。

4

1 に答える 1

0

使ってみて

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

空でないことを確認してください.なぜ Me.Components Nothing なのですか?

于 2012-08-02T18:22:52.030 に答える