VB.NET - Iterating through controls in a container object

后端 未结 10 1296
别那么骄傲
别那么骄傲 2020-12-03 05:18

I have a form with a \"Clear\" button.

When the user clicks \"Clear\", I want to clear the value of all the visible elements on the form. In the case of date contro

10条回答
  •  抹茶落季
    2020-12-03 05:38

    This May Help in Future Development ...

    GetAllButtons(Me)
    
    Public Sub GetAllButtons(ByRef forms As Object)
        Dim list As New List(Of Button)
        Dim iIndx As Integer
        For Each c In forms.Controls
            For iIndx = 0 To forms.Controls.Count - 1
                If (TypeOf forms.Controls(iIndx) Is Button) Then
                    list.Add(forms.Controls(iIndx))
                End If
                If (TypeOf forms.controls(iIndx) Is Panel) Then
                    For Each cntrl As Control In forms.controls(iIndx).Controls
                        If TypeOf cntrl Is Button Then
                            list.Add(cntrl)
                        End If
                    Next
                End If
            Next
        Next
    
    Button(list.ToArray)
    
    End Sub
    
    Public Sub Button(btn() As Button)
        For Each bt In btn
           Do Something with Buttons
        next
    End Sub
    

提交回复
热议问题