2012-08-02 3 views
0

보안 수준에 따라 활성화/비활성화 된 여러 항목이있는 프로젝트가 있습니다. 양식의 모든 컨트롤을 반복하여 이름을 가져오고 목록을 생성하려고합니다. 나는 컨트롤과 그들의 아이들을위한 모든 이름을 얻을 수 있지만 그것이 가지고있는 컨텍스트 메뉴를 모두 찾지는 못한다. 디자인 중에 SeC# ???의 모든 보안 항목에 이름을지었습니다. 지금까지 제가 가지고있는 코드는 다음과 같습니다. 컨트롤의 이름을 찾아 목록에 추가합니다. 바인딩 네비게이터 인 경우 메뉴 항목을 검색하고 Sec 태그가있는 항목을 추가합니다. 내 컨텍스트 메뉴 모두에 대해 동일한 작업을 수행하려면 어떻게해야합니까?VB Net : 보안 수준에 따라 메뉴/컨텍스트 메뉴 항목을 활성화하십시오.

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)는 프로세스를 시작하는 데 사용됩니다.

답변

0

시도

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?

관련 문제