VB.NET - Iterating through controls in a container object

后端 未结 10 1362
别那么骄傲
别那么骄傲 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:49

    I present you my ControlIterator Class

    Source: http://pastebin.com/dubt4nPG

    Some usage examples:

     ControlIterator.Disable(CheckBox1)
    
     ControlIterator.Enable({CheckBox1, CheckBox2})
    
     ControlIterator.Check(Of CheckBox)(Me)
    
     ControlIterator.Uncheck(Of CheckBox)(Me.GroupBox1)
    
     ControlIterator.Hide(Of CheckBox)("1")
    
     ControlIterator.PerformAction(Of CheckBox)(Sub(ctrl As CheckBox) ctrl.Visible = True)
    
     ControlIterator.AsyncPerformAction(RichTextBox1,
                                        Sub(rb As RichTextBox)
                                            For n As Integer = 0 To 9
                                                rb.AppendText(CStr(n))
                                            Next
                                        End Sub)
    
     ControlIterator.PerformAction(Me.Controls, Sub(c As Control)
                                                    c.BackColor = Color.Green
                                                End Sub)
    

提交回复
热议问题