PiToLoKo

ControlIterator by Elektro

Feb 21st, 2014
588
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ' [ Control Iterator ]
  3. '
  4. ' By Elektro H@cker
  5.  
  6. #Region " Usage Examples "
  7.  
  8. ' ControlIterator.Disable(CheckBox1)
  9. '
  10. ' ControlIterator.Enable({CheckBox1, CheckBox2})
  11. '
  12. ' ControlIterator.Check(Of CheckBox)(Me)
  13. '
  14. ' ControlIterator.Uncheck(Of CheckBox)(Me.GroupBox1)
  15. '
  16. ' ControlIterator.Hide(Of CheckBox)("1")
  17. '
  18. ' ControlIterator.PerformAction(Of CheckBox)(Sub(ctrl As CheckBox) ctrl.Visible = True)
  19. '
  20. ' ControlIterator.AsyncPerformAction(RichTextBox1,
  21. '                                    Sub(rb As RichTextBox)
  22. '                                        For n As Integer = 0 To 9
  23. '                                            rb.AppendText(CStr(n))
  24. '                                        Next
  25. '                                    End Sub)
  26. '
  27. ' ControlIterator.PerformAction(Me.Controls, Sub(c As Control)
  28. '                                                c.BackColor = Color.Green
  29. '                                            End Sub)
  30.  
  31. #End Region
  32.  
  33. #Region " Control Iterator "
  34.  
  35. ''' <summary>
  36. ''' Iterates a serie of Controls to perform an operation.
  37. ''' </summary>
  38. Public Class ControlIterator
  39.  
  40. #Region " Public Methods "
  41.  
  42. #Region " Enable "
  43.  
  44. #Region " Synchronous "
  45.  
  46.     ''' <summary>
  47.     ''' Enable an specific Control.
  48.     ''' </summary>
  49.     ''' <param name="Control">Indicates the Control to enable.</param>
  50.     Public Shared Function Enable(ByVal Control As Object) As Boolean
  51.         Return EnableOrDisable({Control}, True)
  52.     End Function
  53.  
  54.     ''' <summary>
  55.     ''' Enable multiple Controls at once.
  56.     ''' </summary>
  57.     ''' <param name="Controls">Indicates the Controls to enable.</param>
  58.     Public Shared Function Enable(ByVal Controls As IEnumerable(Of Object)) As Boolean
  59.         Return EnableOrDisable(Controls, True)
  60.     End Function
  61.  
  62.     ''' <summary>
  63.     ''' Enable all the Controls of the specified Type on the active Formulary.
  64.     ''' </summary>
  65.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  66.     Public Shared Function Enable(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  67.  
  68.         Return EnableOrDisable(Form.ActiveForm.Controls.OfType(Of T).
  69.                         Where(Function(ctrl) Not CType(ctrl, Object).Enabled), True, ContainsName)
  70.  
  71.     End Function
  72.  
  73.     ''' <summary>
  74.     ''' Enable all the Controls of the specified Type on the specified Control Container.
  75.     ''' </summary>
  76.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  77.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  78.     Public Shared Function Enable(Of T)(ByVal ControlContainer As Control,
  79.                                         Optional ByVal ContainsName As String = Nothing) As Boolean
  80.  
  81.         Return EnableOrDisable(ControlContainer.Controls.OfType(Of T).
  82.                         Where(Function(ctrl) Not CType(ctrl, Object).Enabled), True, ContainsName)
  83.  
  84.     End Function
  85.  
  86.     ''' <summary>
  87.     ''' Enable all the Controls of the specified Type on the specified Control Collection.
  88.     ''' </summary>
  89.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  90.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  91.     Public Function Enable(Of T)(ByVal ControlCollection As Control.ControlCollection,
  92.                                  Optional ByVal ContainsName As String = Nothing) As Boolean
  93.  
  94.         Return EnableOrDisable(ControlCollection.OfType(Of T).
  95.                         Where(Function(ctrl) Not CType(ctrl, Object).Enabled), True, ContainsName)
  96.  
  97.     End Function
  98.  
  99. #End Region
  100.  
  101. #Region " Asynchronous "
  102.  
  103.     ''' <summary>
  104.     ''' Asynchronouslly Enable an specific Control.
  105.     ''' </summary>
  106.     ''' <param name="Control">Indicates the Control to enable.</param>
  107.     Public Shared Function AsyncEnable(ByVal Control As Object) As Boolean
  108.         Return AsyncEnableOrDisable({Control}, True)
  109.     End Function
  110.  
  111.     ''' <summary>
  112.     ''' Asynchronouslly Enable multiple Controls at once.
  113.     ''' </summary>
  114.     ''' <param name="Controls">Indicates the Controls to enable.</param>
  115.     Public Shared Function AsyncEnable(ByVal Controls As IEnumerable(Of Object)) As Boolean
  116.         Return AsyncEnableOrDisable(Controls, True)
  117.     End Function
  118.  
  119.     ''' <summary>
  120.     ''' Asynchronouslly Enable all the Controls of the specified Type on the active Formulary.
  121.     ''' </summary>
  122.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  123.     Public Shared Function AsyncEnable(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  124.  
  125.         Return AsyncEnableOrDisable(Form.ActiveForm.Controls.OfType(Of T).
  126.                              Where(Function(ctrl) Not CType(ctrl, Object).Enabled), True, ContainsName)
  127.  
  128.     End Function
  129.  
  130.     ''' <summary>
  131.     ''' Asynchronouslly Enable all the Controls of the specified Type on the specified Control Container.
  132.     ''' </summary>
  133.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  134.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  135.     Public Shared Function AsyncEnable(Of T)(ByVal ControlContainer As Control,
  136.                                              Optional ByVal ContainsName As String = Nothing) As Boolean
  137.  
  138.         Return AsyncEnableOrDisable(ControlContainer.Controls.OfType(Of T).
  139.                              Where(Function(ctrl) Not CType(ctrl, Object).Enabled), True, ContainsName)
  140.  
  141.     End Function
  142.  
  143.     ''' <summary>
  144.     ''' Asynchronouslly Enable all the Controls of the specified Type on the specified Control Collection.
  145.     ''' </summary>
  146.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  147.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  148.     Public Function AsyncEnable(Of T)(ByVal ControlCollection As Control.ControlCollection,
  149.                                       Optional ByVal ContainsName As String = Nothing) As Boolean
  150.  
  151.         Return AsyncEnableOrDisable(ControlCollection.OfType(Of T).
  152.                              Where(Function(ctrl) Not CType(ctrl, Object).Enabled), True, ContainsName)
  153.  
  154.     End Function
  155.  
  156. #End Region
  157.  
  158. #End Region
  159.  
  160. #Region " Disable "
  161.  
  162. #Region " Synchronous "
  163.  
  164.     ''' <summary>
  165.     ''' Disable an specific Control.
  166.     ''' </summary>
  167.     ''' <param name="Control">Indicates the Control to disable.</param>
  168.     Public Shared Function Disable(ByVal Control As Object) As Boolean
  169.         Return EnableOrDisable({Control}, False)
  170.     End Function
  171.  
  172.     ''' <summary>
  173.     ''' Disable multiple Controls at once.
  174.     ''' </summary>
  175.     ''' <param name="Controls">Indicates the Controls to disable.</param>
  176.     Public Shared Function Disable(ByVal Controls As IEnumerable(Of Object)) As Boolean
  177.         Return EnableOrDisable(Controls, False)
  178.     End Function
  179.  
  180.     ''' <summary>
  181.     ''' Disable all the Controls of the specified Type on the active Formulary.
  182.     ''' </summary>
  183.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  184.     Public Shared Function Disable(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  185.  
  186.         Return EnableOrDisable(Form.ActiveForm.Controls.OfType(Of T).
  187.                         Where(Function(ctrl) CType(ctrl, Object).Enabled), False, ContainsName)
  188.  
  189.     End Function
  190.  
  191.     ''' <summary>
  192.     ''' Disable all the Controls of the specified Type on the specified Control Container.
  193.     ''' </summary>
  194.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  195.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  196.     Public Shared Function Disable(Of T)(ByVal ControlContainer As Control,
  197.                                          Optional ByVal ContainsName As String = Nothing) As Boolean
  198.  
  199.         Return EnableOrDisable(ControlContainer.Controls.OfType(Of T).
  200.                         Where(Function(ctrl) CType(ctrl, Object).Enabled), False, ContainsName)
  201.  
  202.     End Function
  203.  
  204.     ''' <summary>
  205.     ''' Disable all the Controls of the specified Type on the specified Control Collection.
  206.     ''' </summary>
  207.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  208.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  209.     Public Shared Function Disable(Of T)(ByVal ControlCollection As Control.ControlCollection,
  210.                                          Optional ByVal ContainsName As String = Nothing) As Boolean
  211.  
  212.         Return EnableOrDisable(ControlCollection.OfType(Of T).
  213.                         Where(Function(ctrl) CType(ctrl, Object).Enabled), False, ContainsName)
  214.  
  215.     End Function
  216.  
  217. #End Region
  218.  
  219. #Region " Asynchronous "
  220.  
  221.     ''' <summary>
  222.     ''' Asynchronouslly Disable an specific Control.
  223.     ''' </summary>
  224.     ''' <param name="Control">Indicates the Control to disable.</param>
  225.     Public Shared Function AsyncDisable(ByVal Control As Object) As Boolean
  226.         Return AsyncEnableOrDisable({Control}, False)
  227.     End Function
  228.  
  229.     ''' <summary>
  230.     ''' Asynchronouslly Disable multiple Controls at once.
  231.     ''' </summary>
  232.     ''' <param name="Controls">Indicates the Controls to disable.</param>
  233.     Public Shared Function AsyncDisable(ByVal Controls As IEnumerable(Of Object)) As Boolean
  234.         Return AsyncEnableOrDisable(Controls, False)
  235.     End Function
  236.  
  237.     ''' <summary>
  238.     ''' Asynchronouslly Disable all the Controls of the specified Type on the active Formulary.
  239.     ''' </summary>
  240.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  241.     Public Shared Function AsyncDisable(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  242.  
  243.         Return AsyncEnableOrDisable(Form.ActiveForm.Controls.OfType(Of T).
  244.                              Where(Function(ctrl) CType(ctrl, Object).Enabled), False, ContainsName)
  245.  
  246.     End Function
  247.  
  248.     ''' <summary>
  249.     ''' Asynchronouslly Disable all the Controls of the specified Type on the specified Control Container.
  250.     ''' </summary>
  251.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  252.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  253.     Public Shared Function AsyncDisable(Of T)(ByVal ControlContainer As Control,
  254.                                               Optional ByVal ContainsName As String = Nothing) As Boolean
  255.  
  256.         Return AsyncEnableOrDisable(ControlContainer.Controls.OfType(Of T).
  257.                              Where(Function(ctrl) CType(ctrl, Object).Enabled), False, ContainsName)
  258.  
  259.     End Function
  260.  
  261.     ''' <summary>
  262.     ''' Asynchronouslly Disable all the Controls of the specified Type on the specified Control Collection.
  263.     ''' </summary>
  264.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  265.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  266.     Public Shared Function AsyncDisable(Of T)(ByVal ControlCollection As Control.ControlCollection,
  267.                                               Optional ByVal ContainsName As String = Nothing) As Boolean
  268.  
  269.         Return AsyncEnableOrDisable(ControlCollection.OfType(Of T).
  270.                              Where(Function(ctrl) CType(ctrl, Object).Enabled), False, ContainsName)
  271.  
  272.     End Function
  273.  
  274. #End Region
  275.  
  276. #End Region
  277.  
  278. #Region " Show "
  279.  
  280. #Region " Synchronous "
  281.  
  282.     ''' <summary>
  283.     ''' Show an specific Control.
  284.     ''' </summary>
  285.     ''' <param name="Control">Indicates the Control to show.</param>
  286.     Public Shared Function Show(ByVal Control As Object) As Boolean
  287.         Return ShowOrHide({Control}, True)
  288.     End Function
  289.  
  290.     ''' <summary>
  291.     ''' Show multiple Controls at once.
  292.     ''' </summary>
  293.     ''' <param name="Controls">Indicates the Controls to show.</param>
  294.     Public Shared Function Show(ByVal Controls As IEnumerable(Of Object)) As Boolean
  295.         Return ShowOrHide(Controls, True)
  296.     End Function
  297.  
  298.     ''' <summary>
  299.     ''' Show all the Controls of the specified Type on the active Formulary.
  300.     ''' </summary>
  301.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  302.     Public Shared Function Show(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  303.  
  304.         Return ShowOrHide(Form.ActiveForm.Controls.OfType(Of T).
  305.                    Where(Function(ctrl) Not CType(ctrl, Object).Visible), True, ContainsName)
  306.  
  307.     End Function
  308.  
  309.     ''' <summary>
  310.     ''' Show all the Controls of the specified Type on the specified Container.
  311.     ''' </summary>
  312.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  313.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  314.     Public Shared Function Show(Of T)(ByVal ControlContainer As Control,
  315.                                       Optional ByVal ContainsName As String = Nothing) As Boolean
  316.  
  317.         Return ShowOrHide(ControlContainer.Controls.OfType(Of T).
  318.                    Where(Function(ctrl) Not CType(ctrl, Object).Visible), True, ContainsName)
  319.  
  320.     End Function
  321.  
  322.     ''' <summary>
  323.     ''' Show all the Controls of the specified Type on the specified Control Collection.
  324.     ''' </summary>
  325.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  326.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  327.     Public Shared Function Show(Of T)(ByVal ControlCollection As Control.ControlCollection,
  328.                                       Optional ByVal ContainsName As String = Nothing) As Boolean
  329.  
  330.         Return ShowOrHide(ControlCollection.OfType(Of T).
  331.                    Where(Function(ctrl) Not CType(ctrl, Object).Visible), True, ContainsName)
  332.  
  333.     End Function
  334.  
  335. #End Region
  336.  
  337. #Region " Asynchronous "
  338.  
  339.     ''' <summary>
  340.     ''' Asynchronouslly Show an specific Control.
  341.     ''' </summary>
  342.     ''' <param name="Control">Indicates the Control to show.</param>
  343.     Public Shared Function AsyncShow(ByVal Control As Object) As Boolean
  344.         Return AsyncShowOrHide({Control}, True)
  345.     End Function
  346.  
  347.     ''' <summary>
  348.     ''' Asynchronouslly Show multiple Controls at once.
  349.     ''' </summary>
  350.     ''' <param name="Controls">Indicates the Controls to show.</param>
  351.     Public Shared Function AsyncShow(ByVal Controls As IEnumerable(Of Object)) As Boolean
  352.         Return AsyncShowOrHide(Controls, True)
  353.     End Function
  354.  
  355.     ''' <summary>
  356.     ''' Asynchronouslly Show all the Controls of the specified Type on the active Formulary.
  357.     ''' </summary>
  358.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  359.     Public Shared Function AsyncShow(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  360.  
  361.         Return AsyncShowOrHide(Form.ActiveForm.Controls.OfType(Of T).
  362.                         Where(Function(ctrl) Not CType(ctrl, Object).Visible), True, ContainsName)
  363.  
  364.     End Function
  365.  
  366.     ''' <summary>
  367.     ''' Asynchronouslly Show all the Controls of the specified Type on the specified Container.
  368.     ''' </summary>
  369.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  370.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  371.     Public Shared Function AsyncShow(Of T)(ByVal ControlContainer As Control,
  372.                                            Optional ByVal ContainsName As String = Nothing) As Boolean
  373.  
  374.         Return AsyncShowOrHide(ControlContainer.Controls.OfType(Of T).
  375.                         Where(Function(ctrl) Not CType(ctrl, Object).Visible), True, ContainsName)
  376.  
  377.     End Function
  378.  
  379.     ''' <summary>
  380.     ''' Asynchronouslly Show all the Controls of the specified Type on the specified Control Collection.
  381.     ''' </summary>
  382.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  383.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  384.     Public Shared Function AsyncShow(Of T)(ByVal ControlCollection As Control.ControlCollection,
  385.                                            Optional ByVal ContainsName As String = Nothing) As Boolean
  386.  
  387.         Return AsyncShowOrHide(ControlCollection.OfType(Of T).
  388.                         Where(Function(ctrl) Not CType(ctrl, Object).Visible), True, ContainsName)
  389.  
  390.     End Function
  391.  
  392. #End Region
  393.  
  394. #End Region
  395.  
  396. #Region " Hide "
  397.  
  398. #Region " Synchronous "
  399.  
  400.     ''' <summary>
  401.     ''' Hide an specific Control.
  402.     ''' </summary>
  403.     ''' <param name="Control">Indicates the Control to hide.</param>
  404.     Public Shared Function Hide(ByVal Control As Object) As Boolean
  405.         Return ShowOrHide({Control}, False)
  406.     End Function
  407.  
  408.     ''' <summary>
  409.     ''' Hide multiple Controls at once.
  410.     ''' </summary>
  411.     ''' <param name="Controls">Indicates the Controls to hide.</param>
  412.     Public Shared Function Hide(ByVal Controls As IEnumerable(Of Object)) As Boolean
  413.         Return ShowOrHide(Controls, False)
  414.     End Function
  415.  
  416.     ''' <summary>
  417.     ''' Hide all the Controls of the specified Type on the active Formulary.
  418.     ''' </summary>
  419.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  420.     Public Shared Function Hide(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  421.  
  422.         Return ShowOrHide(Form.ActiveForm.Controls.OfType(Of T).
  423.                    Where(Function(ctrl) CType(ctrl, Object).Visible), False, ContainsName)
  424.  
  425.     End Function
  426.  
  427.     ''' <summary>
  428.     ''' Hide all the Controls of the specified Type on the specified Container.
  429.     ''' </summary>
  430.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  431.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  432.     Public Shared Function Hide(Of T)(ByVal ControlContainer As Control,
  433.                                       Optional ByVal ContainsName As String = Nothing) As Boolean
  434.  
  435.         Return ShowOrHide(ControlContainer.Controls.OfType(Of T).
  436.                    Where(Function(ctrl) CType(ctrl, Object).Visible), False, ContainsName)
  437.  
  438.     End Function
  439.  
  440.     ''' <summary>
  441.     ''' Hide all the Controls of the specified Type on the specified Control Collection.
  442.     ''' </summary>
  443.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  444.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  445.     Public Shared Function Hide(Of T)(ByVal ControlCollection As Control.ControlCollection,
  446.                                       Optional ByVal ContainsName As String = Nothing) As Boolean
  447.  
  448.         Return ShowOrHide(ControlCollection.OfType(Of T).
  449.                    Where(Function(ctrl) CType(ctrl, Object).Visible), False, ContainsName)
  450.  
  451.     End Function
  452.  
  453. #End Region
  454.  
  455. #Region " Asynchronous "
  456.  
  457.     ''' <summary>
  458.     ''' Asynchronouslly Hide an specific Control.
  459.     ''' </summary>
  460.     ''' <param name="Control">Indicates the Control to hide.</param>
  461.     Public Shared Function AsyncHide(ByVal Control As Object) As Boolean
  462.         Return AsyncShowOrHide({Control}, False)
  463.     End Function
  464.  
  465.     ''' <summary>
  466.     ''' Asynchronouslly Hide multiple Controls at once.
  467.     ''' </summary>
  468.     ''' <param name="Controls">Indicates the Controls to hide.</param>
  469.     Public Shared Function AsyncHide(ByVal Controls As IEnumerable(Of Object)) As Boolean
  470.         Return AsyncShowOrHide(Controls, False)
  471.     End Function
  472.  
  473.     ''' <summary>
  474.     ''' Asynchronouslly Hide all the Controls of the specified Type on the active Formulary.
  475.     ''' </summary>
  476.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  477.     Public Shared Function AsyncHide(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  478.  
  479.         Return AsyncShowOrHide(Form.ActiveForm.Controls.OfType(Of T).
  480.                         Where(Function(ctrl) CType(ctrl, Object).Visible), False, ContainsName)
  481.  
  482.     End Function
  483.  
  484.     ''' <summary>
  485.     ''' Asynchronouslly Hide all the Controls of the specified Type on the specified Container.
  486.     ''' </summary>
  487.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  488.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  489.     Public Shared Function AsyncHide(Of T)(ByVal ControlContainer As Control,
  490.                                            Optional ByVal ContainsName As String = Nothing) As Boolean
  491.  
  492.         Return AsyncShowOrHide(ControlContainer.Controls.OfType(Of T).
  493.                         Where(Function(ctrl) CType(ctrl, Object).Visible), False, ContainsName)
  494.  
  495.     End Function
  496.  
  497.     ''' <summary>
  498.     ''' Asynchronouslly Hide all the Controls of the specified Type on the specified Control Collection.
  499.     ''' </summary>
  500.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  501.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  502.     Public Shared Function AsyncHide(Of T)(ByVal ControlCollection As Control.ControlCollection,
  503.                                            Optional ByVal ContainsName As String = Nothing) As Boolean
  504.  
  505.         Return AsyncShowOrHide(ControlCollection.OfType(Of T).
  506.                         Where(Function(ctrl) CType(ctrl, Object).Visible), False, ContainsName)
  507.  
  508.     End Function
  509.  
  510. #End Region
  511.  
  512. #End Region
  513.  
  514. #Region " Check "
  515.  
  516. #Region " Synchronous "
  517.  
  518.     ''' <summary>
  519.     ''' Check an specific Control.
  520.     ''' </summary>
  521.     ''' <param name="Control">Indicates the Control to check.</param>
  522.     Public Shared Function Check(ByVal Control As Object) As Boolean
  523.         Return CheckOrUncheck({Control}, True)
  524.     End Function
  525.  
  526.     ''' <summary>
  527.     ''' Check multiple Controls at once.
  528.     ''' </summary>
  529.     ''' <param name="Controls">Indicates the Controls to check.</param>
  530.     Public Shared Function Check(ByVal Controls As IEnumerable(Of Object)) As Boolean
  531.         Return CheckOrUncheck(Controls, True)
  532.     End Function
  533.  
  534.     ''' <summary>
  535.     ''' Check all the Controls of the specified Type on the active Formulary.
  536.     ''' </summary>
  537.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  538.     Public Shared Function Check(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  539.  
  540.         Return CheckOrUncheck(Form.ActiveForm.Controls.OfType(Of T).
  541.                        Where(Function(ctrl) Not CType(ctrl, Object).Checked), True, ContainsName)
  542.  
  543.     End Function
  544.  
  545.     ''' <summary>
  546.     ''' Check all the Controls of the specified Type on the specified Control Container.
  547.     ''' </summary>
  548.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  549.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  550.     Public Shared Function Check(Of T)(ByVal ControlContainer As Control,
  551.                                        Optional ByVal ContainsName As String = Nothing) As Boolean
  552.  
  553.         Return CheckOrUncheck(ControlContainer.Controls.OfType(Of T).
  554.                        Where(Function(ctrl) Not CType(ctrl, Object).Checked), True, ContainsName)
  555.  
  556.     End Function
  557.  
  558.     ''' <summary>
  559.     ''' Check all the Controls of the specified Type on the specified Control Collection.
  560.     ''' </summary>
  561.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  562.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  563.     Public Shared Function Check(Of T)(ByVal ControlCollection As Control.ControlCollection,
  564.                                        Optional ByVal ContainsName As String = Nothing) As Boolean
  565.  
  566.         Return CheckOrUncheck(ControlCollection.OfType(Of T).
  567.                        Where(Function(ctrl) Not CType(ctrl, Object).Checked), True, ContainsName)
  568.  
  569.     End Function
  570.  
  571. #End Region
  572.  
  573. #Region " Asynchronous "
  574.  
  575.     ''' <summary>
  576.     ''' Asynchronouslly Check an specific Control.
  577.     ''' </summary>
  578.     ''' <param name="Control">Indicates the Control to check.</param>
  579.     Public Shared Function AsyncCheck(ByVal Control As Object) As Boolean
  580.         Return AsyncCheckOrUncheck({Control}, True)
  581.     End Function
  582.  
  583.     ''' <summary>
  584.     ''' Asynchronouslly Check multiple Controls at once.
  585.     ''' </summary>
  586.     ''' <param name="Controls">Indicates the Controls to check.</param>
  587.     Public Shared Function AsyncCheck(ByVal Controls As IEnumerable(Of Object)) As Boolean
  588.         Return AsyncCheckOrUncheck(Controls, True)
  589.     End Function
  590.  
  591.     ''' <summary>
  592.     ''' Asynchronouslly Check all the Controls of the specified Type on the active Formulary.
  593.     ''' </summary>
  594.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  595.     Public Shared Function AsyncCheck(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  596.  
  597.         Return AsyncCheckOrUncheck(Form.ActiveForm.Controls.OfType(Of T).
  598.                             Where(Function(ctrl) Not CType(ctrl, Object).Checked), True, ContainsName)
  599.  
  600.     End Function
  601.  
  602.     ''' <summary>
  603.     ''' Asynchronouslly Check all the Controls of the specified Type on the specified Control Container.
  604.     ''' </summary>
  605.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  606.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  607.     Public Shared Function AsyncCheck(Of T)(ByVal ControlContainer As Control,
  608.                                             Optional ByVal ContainsName As String = Nothing) As Boolean
  609.  
  610.         Return AsyncCheckOrUncheck(ControlContainer.Controls.OfType(Of T).
  611.                             Where(Function(ctrl) Not CType(ctrl, Object).Checked), True, ContainsName)
  612.  
  613.     End Function
  614.  
  615.     ''' <summary>
  616.     ''' Asynchronouslly Check all the Controls of the specified Type on the specified Control Collection.
  617.     ''' </summary>
  618.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  619.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  620.     Public Shared Function AsyncCheck(Of T)(ByVal ControlCollection As Control.ControlCollection,
  621.                                             Optional ByVal ContainsName As String = Nothing) As Boolean
  622.  
  623.         Return AsyncCheckOrUncheck(ControlCollection.OfType(Of T).
  624.                             Where(Function(ctrl) Not CType(ctrl, Object).Checked), True, ContainsName)
  625.  
  626.     End Function
  627.  
  628. #End Region
  629.  
  630. #End Region
  631.  
  632. #Region " Uncheck "
  633.  
  634. #Region " Synchronous "
  635.  
  636.     ''' <summary>
  637.     ''' Uncheck an specific Control.
  638.     ''' </summary>
  639.     ''' <param name="Control">Indicates the Control to uncheck.</param>
  640.     Public Shared Function Uncheck(ByVal Control As Object) As Boolean
  641.         Return CheckOrUncheck({Control}, False)
  642.     End Function
  643.  
  644.     ''' <summary>
  645.     ''' Uncheck multiple Controls at once.
  646.     ''' </summary>
  647.     ''' <param name="Controls">Indicates the Controls to uncheck.</param>
  648.     Public Shared Function Uncheck(ByVal Controls As IEnumerable(Of Object)) As Boolean
  649.         Return CheckOrUncheck(Controls, False)
  650.  
  651.     End Function
  652.  
  653.     ''' <summary>
  654.     ''' Uncheck all the Controls of the specified Type on the active Formulary.
  655.     ''' </summary>
  656.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  657.     Public Shared Function Uncheck(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  658.  
  659.         Return CheckOrUncheck(Form.ActiveForm.Controls.OfType(Of T).
  660.                        Where(Function(ctrl) CType(ctrl, Object).Checked), False, ContainsName)
  661.  
  662.     End Function
  663.  
  664.     ''' <summary>
  665.     ''' Uncheck all the Controls of the specified Type on the specified Control Container.
  666.     ''' </summary>
  667.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  668.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  669.     Public Shared Function Uncheck(Of T)(ByVal ControlContainer As Control,
  670.                                          Optional ByVal ContainsName As String = Nothing) As Boolean
  671.  
  672.         Return CheckOrUncheck(ControlContainer.Controls.OfType(Of T).
  673.                        Where(Function(ctrl) CType(ctrl, Object).Checked), False, ContainsName)
  674.  
  675.     End Function
  676.  
  677.     ''' <summary>
  678.     ''' Uncheck all the Controls of the specified Type on the specified Control Collection.
  679.     ''' </summary>
  680.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  681.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  682.     Public Shared Function Uncheck(Of T)(ByVal ControlCollection As Control.ControlCollection,
  683.                                          Optional ByVal ContainsName As String = Nothing) As Boolean
  684.  
  685.         Return CheckOrUncheck(ControlCollection.OfType(Of T).
  686.                        Where(Function(ctrl) CType(ctrl, Object).Checked), False, ContainsName)
  687.  
  688.     End Function
  689.  
  690. #End Region
  691.  
  692. #Region " Asynchronous "
  693.  
  694.     ''' <summary>
  695.     ''' Asynchronouslly Uncheck an specific Control.
  696.     ''' </summary>
  697.     ''' <param name="Control">Indicates the Control to uncheck.</param>
  698.     Public Shared Function AsyncUncheck(ByVal Control As Object) As Boolean
  699.         Return AsyncCheckOrUncheck({Control}, False)
  700.     End Function
  701.  
  702.     ''' <summary>
  703.     ''' Asynchronouslly Uncheck multiple Controls at once.
  704.     ''' </summary>
  705.     ''' <param name="Controls">Indicates the Controls to uncheck.</param>
  706.     Public Shared Function AsyncUncheck(ByVal Controls As IEnumerable(Of Object)) As Boolean
  707.         Return AsyncCheckOrUncheck(Controls, False)
  708.     End Function
  709.  
  710.     ''' <summary>
  711.     ''' Asynchronouslly Uncheck all the Controls of the specified Type on the active Formulary.
  712.     ''' </summary>
  713.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  714.     Public Shared Function AsyncUncheck(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  715.  
  716.         Return AsyncCheckOrUncheck(Form.ActiveForm.Controls.OfType(Of T).
  717.                             Where(Function(ctrl) CType(ctrl, Object).Checked), False, ContainsName)
  718.  
  719.     End Function
  720.  
  721.     ''' <summary>
  722.     ''' Asynchronouslly Uncheck all the Controls of the specified Type on the specified Control Container.
  723.     ''' </summary>
  724.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  725.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  726.     Public Shared Function AsyncUncheck(Of T)(ByVal ControlContainer As Control,
  727.                                               Optional ByVal ContainsName As String = Nothing) As Boolean
  728.  
  729.         Return AsyncCheckOrUncheck(ControlContainer.Controls.OfType(Of T).
  730.                             Where(Function(ctrl) CType(ctrl, Object).Checked), False, ContainsName)
  731.  
  732.     End Function
  733.  
  734.     ''' <summary>
  735.     ''' Asynchronouslly Uncheck all the Controls of the specified Type on the specified Control Collection.
  736.     ''' </summary>
  737.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  738.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  739.     Public Shared Function AsyncUncheck(Of T)(ByVal ControlCollection As Control.ControlCollection,
  740.                                               Optional ByVal ContainsName As String = Nothing) As Boolean
  741.  
  742.         Return AsyncCheckOrUncheck(ControlCollection.OfType(Of T).
  743.                             Where(Function(ctrl) CType(ctrl, Object).Checked), False, ContainsName)
  744.  
  745.     End Function
  746.  
  747. #End Region
  748.  
  749. #End Region
  750.  
  751. #Region " Dispose "
  752.  
  753. #Region " Synchronous "
  754.  
  755.     ''' <summary>
  756.     ''' Dispose an specific Control.
  757.     ''' </summary>
  758.     ''' <param name="Control">Indicates the Control to dispose.</param>
  759.     Public Shared Function Dispose(ByVal Control As Object) As Boolean
  760.         Return DisposeControls({Control})
  761.     End Function
  762.  
  763.     ''' <summary>
  764.     ''' Dispose multiple Controls at once.
  765.     ''' </summary>
  766.     ''' <param name="Controls">Indicates the Controls to dispose.</param>
  767.     Public Shared Function Dispose(ByVal Controls As IEnumerable(Of Object)) As Boolean
  768.         Return DisposeControls(Controls)
  769.     End Function
  770.  
  771.     ''' <summary>
  772.     ''' Dispose all the Controls of the specified Type on the active Formulary.
  773.     ''' </summary>
  774.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  775.     Public Shared Function Dispose(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  776.  
  777.         Return DisposeControls(Form.ActiveForm.Controls.OfType(Of T).
  778.                         Where(Function(ctrl) Not CType(ctrl, Object).IsDisposed), ContainsName)
  779.  
  780.     End Function
  781.  
  782.     ''' <summary>
  783.     ''' Dispose all the Controls of the specified Type on the specified Control Container.
  784.     ''' </summary>
  785.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  786.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  787.     Public Shared Function Dispose(Of T)(ByVal ControlContainer As Control,
  788.                                          Optional ByVal ContainsName As String = Nothing) As Boolean
  789.  
  790.         Return DisposeControls(ControlContainer.Controls.OfType(Of T).
  791.                         Where(Function(ctrl) Not CType(ctrl, Object).IsDisposed), ContainsName)
  792.  
  793.     End Function
  794.  
  795.     ''' <summary>
  796.     ''' Dispose all the Controls of the specified Type on the specified Control Collection.
  797.     ''' </summary>
  798.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  799.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  800.     Public Shared Function Dispose(Of T)(ByVal ControlCollection As Control.ControlCollection,
  801.                                          Optional ByVal ContainsName As String = Nothing) As Boolean
  802.  
  803.         Return DisposeControls(ControlCollection.OfType(Of T).
  804.                         Where(Function(ctrl) Not CType(ctrl, Object).IsDisposed), ContainsName)
  805.  
  806.     End Function
  807.  
  808. #End Region
  809.  
  810. #Region " Asynchronous "
  811.  
  812.     ''' <summary>
  813.     ''' Asynchronouslly Dispose an specific Control.
  814.     ''' </summary>
  815.     ''' <param name="Control">Indicates the Control to dispose.</param>
  816.     Public Shared Function AsyncDispose(ByVal Control As Object) As Boolean
  817.         Return AsyncDisposeControls({Control})
  818.     End Function
  819.  
  820.     ''' <summary>
  821.     ''' Asynchronouslly Dispose multiple Controls at once.
  822.     ''' </summary>
  823.     ''' <param name="Controls">Indicates the Controls to dispose.</param>
  824.     Public Shared Function AsyncDispose(ByVal Controls As IEnumerable(Of Object)) As Boolean
  825.         Return AsyncDisposeControls(Controls)
  826.     End Function
  827.  
  828.     ''' <summary>
  829.     ''' Asynchronouslly Dispose all the Controls of the specified Type on the active Formulary.
  830.     ''' </summary>
  831.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  832.     Public Shared Function AsyncDispose(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  833.  
  834.         Return AsyncDisposeControls(Form.ActiveForm.Controls.OfType(Of T).
  835.                              Where(Function(ctrl) Not CType(ctrl, Object).IsDisposed), ContainsName)
  836.  
  837.     End Function
  838.  
  839.     ''' <summary>
  840.     ''' Asynchronouslly Dispose all the Controls of the specified Type on the specified Control Container.
  841.     ''' </summary>
  842.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  843.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  844.     Public Shared Function AsyncDispose(Of T)(ByVal ControlContainer As Control,
  845.                                               Optional ByVal ContainsName As String = Nothing) As Boolean
  846.  
  847.         Return AsyncDisposeControls(ControlContainer.Controls.OfType(Of T).
  848.                              Where(Function(ctrl) Not CType(ctrl, Object).IsDisposed), ContainsName)
  849.  
  850.     End Function
  851.  
  852.     ''' <summary>
  853.     ''' Asynchronouslly Dispose all the Controls of the specified Type on the specified Control Collection.
  854.     ''' </summary>
  855.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  856.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  857.     Public Shared Function AsyncDispose(Of T)(ByVal ControlCollection As Control.ControlCollection,
  858.                                               Optional ByVal ContainsName As String = Nothing) As Boolean
  859.  
  860.         Return AsyncDisposeControls(ControlCollection.OfType(Of T).
  861.                              Where(Function(ctrl) Not CType(ctrl, Object).IsDisposed), ContainsName)
  862.  
  863.     End Function
  864.  
  865. #End Region
  866.  
  867. #End Region
  868.  
  869. #Region " Toggle Enabled "
  870.  
  871. #Region " Synchronous "
  872.  
  873.     ''' <summary>
  874.     ''' Toggle the enabled state of an specific Control.
  875.     ''' </summary>
  876.     ''' <param name="Control">Indicates the Control to toggle their enabled state.</param>
  877.     Public Shared Function ToggleEnabled(ByVal Control As Object) As Boolean
  878.         Return _ToggleEnabled({Control})
  879.     End Function
  880.  
  881.     ''' <summary>
  882.     ''' Toggle the enabled state of multiple Controls at once.
  883.     ''' </summary>
  884.     ''' <param name="Controls">Indicates the Controls to toggle their enabled state.</param>
  885.     Public Shared Function ToggleEnabled(ByVal Controls As IEnumerable(Of Object)) As Boolean
  886.         Return _ToggleEnabled(Controls)
  887.     End Function
  888.  
  889.     ''' <summary>
  890.     ''' Toggle the enabled state of all the Controls of the specified Type on the active Formulary.
  891.     ''' </summary>
  892.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  893.     Public Shared Function ToggleEnabled(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  894.  
  895.         Return _ToggleEnabled(Form.ActiveForm.Controls.OfType(Of T), ContainsName)
  896.  
  897.     End Function
  898.  
  899.     ''' <summary>
  900.     ''' Toggle the enabled state of all the Controls of the specified Type on the specified Control Container.
  901.     ''' </summary>
  902.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  903.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  904.     Public Shared Function ToggleEnabled(Of T)(ByVal ControlContainer As Control,
  905.                                                Optional ByVal ContainsName As String = Nothing) As Boolean
  906.  
  907.         Return _ToggleEnabled(ControlContainer.Controls.OfType(Of T), ContainsName)
  908.  
  909.     End Function
  910.  
  911.     ''' <summary>
  912.     ''' Toggle the enabled state of all the Controls of the specified Type on the specified Control Collection.
  913.     ''' </summary>
  914.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  915.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  916.     Public Shared Function ToggleEnabled(Of T)(ByVal ControlCollection As Control.ControlCollection,
  917.                                                Optional ByVal ContainsName As String = Nothing) As Boolean
  918.  
  919.         Return _ToggleEnabled(ControlCollection.OfType(Of T), ContainsName)
  920.  
  921.     End Function
  922.  
  923. #End Region
  924.  
  925. #Region " Asynchronous "
  926.  
  927.     ''' <summary>
  928.     ''' Asynchronouslly Toggle the enabled state of an specific Control.
  929.     ''' </summary>
  930.     ''' <param name="Control">Indicates the Control to toggle their enabled state.</param>
  931.     Public Shared Function AsyncToggleEnabled(ByVal Control As Object) As Boolean
  932.         Return _AsyncToggleEnabled({Control})
  933.     End Function
  934.  
  935.     ''' <summary>
  936.     ''' Asynchronouslly Toggle the enabled state of multiple Controls at once.
  937.     ''' </summary>
  938.     ''' <param name="Controls">Indicates the Controls to toggle their enabled state.</param>
  939.     Public Shared Function AsyncToggleEnabled(ByVal Controls As IEnumerable(Of Object)) As Boolean
  940.         Return _AsyncToggleEnabled(Controls)
  941.     End Function
  942.  
  943.     ''' <summary>
  944.     ''' Asynchronouslly Toggle the enabled state of all the Controls of the specified Type on the active Formulary.
  945.     ''' </summary>
  946.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  947.     Public Shared Function AsyncToggleEnabled(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  948.  
  949.         Return _AsyncToggleEnabled(Form.ActiveForm.Controls.OfType(Of T), ContainsName)
  950.  
  951.     End Function
  952.  
  953.     ''' <summary>
  954.     ''' Asynchronouslly Toggle the enabled state of all the Controls of the specified Type on the specified Control Container.
  955.     ''' </summary>
  956.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  957.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  958.     Public Shared Function AsyncToggleEnabled(Of T)(ByVal ControlContainer As Control,
  959.                                                     Optional ByVal ContainsName As String = Nothing) As Boolean
  960.  
  961.         Return _AsyncToggleEnabled(ControlContainer.Controls.OfType(Of T), ContainsName)
  962.  
  963.     End Function
  964.  
  965.     ''' <summary>
  966.     ''' Asynchronouslly Toggle the enabled state of all the Controls of the specified Type on the specified Control Collection.
  967.     ''' </summary>
  968.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  969.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  970.     Public Shared Function AsyncToggleEnabled(Of T)(ByVal ControlCollection As Control.ControlCollection,
  971.                                                     Optional ByVal ContainsName As String = Nothing) As Boolean
  972.  
  973.         Return _AsyncToggleEnabled(ControlCollection.OfType(Of T), ContainsName)
  974.  
  975.     End Function
  976.  
  977. #End Region
  978.  
  979. #End Region
  980.  
  981. #Region " Toggle Visible "
  982.  
  983. #Region " Synchronous "
  984.  
  985.     ''' <summary>
  986.     ''' Toggle the visible state of an specific Control.
  987.     ''' </summary>
  988.     ''' <param name="Control">Indicates the Control to toggle their visible state.</param>
  989.     Public Shared Function ToggleVisible(ByVal Control As Object) As Boolean
  990.         Return _ToggleVisible({Control})
  991.     End Function
  992.  
  993.     ''' <summary>
  994.     ''' Toggle the visible state of multiple Controls at once.
  995.     ''' </summary>
  996.     ''' <param name="Controls">Indicates the Controls to toggle their visible state.</param>
  997.     Public Shared Function ToggleVisible(ByVal Controls As IEnumerable(Of Object)) As Boolean
  998.         Return _ToggleVisible(Controls)
  999.     End Function
  1000.  
  1001.     ''' <summary>
  1002.     ''' Toggle the visible state of all the Controls of the specified Type on the active Formulary.
  1003.     ''' </summary>
  1004.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1005.     Public Shared Function ToggleVisible(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  1006.  
  1007.         Return _ToggleVisible(Form.ActiveForm.Controls.OfType(Of T), ContainsName)
  1008.  
  1009.     End Function
  1010.  
  1011.     ''' <summary>
  1012.     ''' Toggle the visible state of all the Controls of the specified Type on the specified Control Container.
  1013.     ''' </summary>
  1014.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  1015.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1016.     Public Shared Function ToggleVisible(Of T)(ByVal ControlContainer As Control,
  1017.                                                Optional ByVal ContainsName As String = Nothing) As Boolean
  1018.  
  1019.         Return _ToggleVisible(ControlContainer.Controls.OfType(Of T), ContainsName)
  1020.  
  1021.     End Function
  1022.  
  1023.     ''' <summary>
  1024.     ''' Toggle the visible state of all the Controls of the specified Type on the specified Control Collection.
  1025.     ''' </summary>
  1026.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  1027.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1028.     Public Shared Function ToggleVisible(Of T)(ByVal ControlCollection As Control.ControlCollection,
  1029.                                                Optional ByVal ContainsName As String = Nothing) As Boolean
  1030.  
  1031.         Return _ToggleVisible(ControlCollection.OfType(Of T), ContainsName)
  1032.  
  1033.     End Function
  1034.  
  1035. #End Region
  1036.  
  1037. #Region " Asynchronous "
  1038.  
  1039.     ''' <summary>
  1040.     ''' Asynchronouslly Toggle the visible state of an specific Control.
  1041.     ''' </summary>
  1042.     ''' <param name="Control">Indicates the Control to toggle their visible state.</param>
  1043.     Public Shared Function AsyncToggleVisible(ByVal Control As Object) As Boolean
  1044.         Return _AsyncToggleVisible({Control})
  1045.     End Function
  1046.  
  1047.     ''' <summary>
  1048.     ''' Asynchronouslly Toggle the visible state of multiple Controls at once.
  1049.     ''' </summary>
  1050.     ''' <param name="Controls">Indicates the Controls to toggle their visible state.</param>
  1051.     Public Shared Function AsyncToggleVisible(ByVal Controls As IEnumerable(Of Object)) As Boolean
  1052.         Return _AsyncToggleVisible(Controls)
  1053.     End Function
  1054.  
  1055.     ''' <summary>
  1056.     ''' Asynchronouslly Toggle the visible state of all the Controls of the specified Type on the active Formulary.
  1057.     ''' </summary>
  1058.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1059.     Public Shared Function AsyncToggleVisible(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  1060.  
  1061.         Return _AsyncToggleVisible(Form.ActiveForm.Controls.OfType(Of T), ContainsName)
  1062.  
  1063.     End Function
  1064.  
  1065.     ''' <summary>
  1066.     ''' Asynchronouslly Toggle the visible state of all the Controls of the specified Type on the specified Control Container.
  1067.     ''' </summary>
  1068.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  1069.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1070.     Public Shared Function AsyncToggleVisible(Of T)(ByVal ControlContainer As Control,
  1071.                                                     Optional ByVal ContainsName As String = Nothing) As Boolean
  1072.  
  1073.         Return _AsyncToggleVisible(ControlContainer.Controls.OfType(Of T), ContainsName)
  1074.  
  1075.     End Function
  1076.  
  1077.     ''' <summary>
  1078.     ''' Asynchronouslly Toggle the visible state of all the Controls of the specified Type on the specified Control Collection.
  1079.     ''' </summary>
  1080.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  1081.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1082.     Public Shared Function AsyncToggleVisible(Of T)(ByVal ControlCollection As Control.ControlCollection,
  1083.                                                     Optional ByVal ContainsName As String = Nothing) As Boolean
  1084.  
  1085.         Return _AsyncToggleVisible(ControlCollection.OfType(Of T), ContainsName)
  1086.  
  1087.     End Function
  1088.  
  1089. #End Region
  1090.  
  1091. #End Region
  1092.  
  1093. #Region " Toggle Checked "
  1094.  
  1095. #Region " Synchronous "
  1096.  
  1097.     ''' <summary>
  1098.     ''' Toggle the checked state of an specific Control.
  1099.     ''' </summary>
  1100.     ''' <param name="Control">Indicates the Control to toggle their checked state.</param>
  1101.     Public Shared Function ToggleChecked(ByVal Control As Object) As Boolean
  1102.         Return _ToggleChecked({Control})
  1103.     End Function
  1104.  
  1105.     ''' <summary>
  1106.     ''' Toggle the checked state of multiple Controls at once.
  1107.     ''' </summary>
  1108.     ''' <param name="Controls">Indicates the Controls to toggle their checked state.</param>
  1109.     Public Shared Function ToggleChecked(ByVal Controls As IEnumerable(Of Object)) As Boolean
  1110.         Return _ToggleChecked(Controls)
  1111.     End Function
  1112.  
  1113.     ''' <summary>
  1114.     ''' Toggle the checked state of all the Controls of the specified Type on the active Formulary.
  1115.     ''' </summary>
  1116.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1117.     Public Shared Function ToggleChecked(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  1118.  
  1119.         Return _ToggleChecked(Form.ActiveForm.Controls.OfType(Of T), ContainsName)
  1120.  
  1121.     End Function
  1122.  
  1123.     ''' <summary>
  1124.     ''' Toggle the checked state of all the Controls of the specified Type on the specified Control Container.
  1125.     ''' </summary>
  1126.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  1127.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1128.     Public Shared Function ToggleChecked(Of T)(ByVal ControlContainer As Control,
  1129.                                                Optional ByVal ContainsName As String = Nothing) As Boolean
  1130.  
  1131.         Return _ToggleChecked(ControlContainer.Controls.OfType(Of T), ContainsName)
  1132.  
  1133.     End Function
  1134.  
  1135.     ''' <summary>
  1136.     ''' Toggle the checked state of all the Controls of the specified Type on the specified Control Collection.
  1137.     ''' </summary>
  1138.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  1139.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1140.     Public Shared Function ToggleChecked(Of T)(ByVal ControlCollection As Control.ControlCollection,
  1141.                                                Optional ByVal ContainsName As String = Nothing) As Boolean
  1142.  
  1143.         Return _ToggleChecked(ControlCollection.OfType(Of T), ContainsName)
  1144.  
  1145.     End Function
  1146.  
  1147. #End Region
  1148.  
  1149. #Region " Asynchronous "
  1150.  
  1151.     ''' <summary>
  1152.     ''' Asynchronouslly Toggle the checked state of an specific Control.
  1153.     ''' </summary>
  1154.     ''' <param name="Control">Indicates the Control to toggle their checked state.</param>
  1155.     Public Shared Function AsyncToggleChecked(ByVal Control As Object) As Boolean
  1156.         Return _AsyncToggleChecked({Control})
  1157.     End Function
  1158.  
  1159.     ''' <summary>
  1160.     ''' Asynchronouslly Toggle the checked state of multiple Controls at once.
  1161.     ''' </summary>
  1162.     ''' <param name="Controls">Indicates the Controls to toggle their checked state.</param>
  1163.     Public Shared Function AsyncToggleChecked(ByVal Controls As IEnumerable(Of Object)) As Boolean
  1164.         Return _AsyncToggleChecked(Controls)
  1165.     End Function
  1166.  
  1167.     ''' <summary>
  1168.     ''' Asynchronouslly Toggle the checked state of all the Controls of the specified Type on the active Formulary.
  1169.     ''' </summary>
  1170.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1171.     Public Shared Function AsyncToggleChecked(Of T)(Optional ByVal ContainsName As String = Nothing) As Boolean
  1172.  
  1173.         Return _AsyncToggleChecked(Form.ActiveForm.Controls.OfType(Of T), ContainsName)
  1174.  
  1175.     End Function
  1176.  
  1177.     ''' <summary>
  1178.     ''' Asynchronouslly Toggle the checked state of all the Controls of the specified Type on the specified Control Container.
  1179.     ''' </summary>
  1180.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  1181.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1182.     Public Shared Function AsyncToggleChecked(Of T)(ByVal ControlContainer As Control,
  1183.                                                     Optional ByVal ContainsName As String = Nothing) As Boolean
  1184.  
  1185.         Return _AsyncToggleChecked(ControlContainer.Controls.OfType(Of T), ContainsName)
  1186.  
  1187.     End Function
  1188.  
  1189.     ''' <summary>
  1190.     ''' Asynchronouslly Toggle the checked state of all the Controls of the specified Type on the specified Control Collection.
  1191.     ''' </summary>
  1192.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  1193.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1194.     Public Shared Function AsyncToggleChecked(Of T)(ByVal ControlCollection As Control.ControlCollection,
  1195.                                                     Optional ByVal ContainsName As String = Nothing) As Boolean
  1196.  
  1197.         Return _AsyncToggleChecked(ControlCollection.OfType(Of T), ContainsName)
  1198.  
  1199.     End Function
  1200.  
  1201. #End Region
  1202.  
  1203. #End Region
  1204.  
  1205. #Region " Perform Action "
  1206.  
  1207. #Region " Synchronous "
  1208.  
  1209.     ''' <summary>
  1210.     ''' Perform an operation on a specific Control.
  1211.     ''' </summary>
  1212.     ''' <param name="Control">Indicates the Control to perform the Action.</param>
  1213.     ''' <param name="Operation">Indicates the Action to perform on the control.</param>
  1214.     Public Shared Function PerformAction(ByVal Control As Object,
  1215.                                          ByVal Operation As [Delegate])
  1216.  
  1217.         Return PerformActionOnControls({Control}, Operation)
  1218.  
  1219.     End Function
  1220.  
  1221.     ''' <summary>
  1222.     ''' Perform an operation on multiple Controls at once.
  1223.     ''' </summary>
  1224.     ''' <param name="Controls">Indicates the Controls to perform the Action.</param>
  1225.     ''' <param name="Operation">Indicates the Action to perform on the controls.</param>
  1226.     Public Shared Function PerformAction(ByVal Controls As IEnumerable(Of Object),
  1227.                                          ByVal Operation As [Delegate])
  1228.  
  1229.         Return PerformActionOnControls(Controls, Operation)
  1230.  
  1231.     End Function
  1232.  
  1233.     ''' <summary>
  1234.     ''' Perform an operation on all the Controls of the specified Type on the active Formulary.
  1235.     ''' </summary>
  1236.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1237.     Public Shared Function PerformAction(Of T)(ByVal Operation As [Delegate],
  1238.                                                Optional ByVal ContainsName As String = Nothing) As Boolean
  1239.  
  1240.         Return PerformActionOnControls(Form.ActiveForm.Controls.OfType(Of T), Operation, ContainsName)
  1241.  
  1242.     End Function
  1243.  
  1244.     ''' <summary>
  1245.     ''' Perform an operation on all the Controls of the specified Type on the specified Control Container.
  1246.     ''' </summary>
  1247.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  1248.     ''' <param name="Operation">Indicates the Action to perform on the controls.</param>
  1249.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1250.     Public Shared Function PerformAction(Of T)(ByVal ControlContainer As Control,
  1251.                                                ByVal Operation As [Delegate],
  1252.                                                Optional ByVal ContainsName As String = Nothing) As Boolean
  1253.  
  1254.         Return PerformActionOnControls(ControlContainer.Controls.OfType(Of T), Operation, ContainsName)
  1255.  
  1256.     End Function
  1257.  
  1258.     ''' <summary>
  1259.     ''' Perform an operation on all the Controls of the specified Type on the specified Control Collection.
  1260.     ''' </summary>
  1261.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  1262.     ''' <param name="Operation">Indicates the Action to perform on the controls.</param>
  1263.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1264.     Public Shared Function PerformAction(Of T)(ByVal ControlCollection As Control.ControlCollection,
  1265.                                                ByVal Operation As [Delegate],
  1266.                                                Optional ByVal ContainsName As String = Nothing) As Boolean
  1267.  
  1268.  
  1269.         Return PerformActionOnControls(ControlCollection.OfType(Of T), Operation, ContainsName)
  1270.  
  1271.     End Function
  1272.  
  1273.     ''' <summary>
  1274.     ''' Perform an operation on all the Controls on the specified Control Collection.
  1275.     ''' </summary>
  1276.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  1277.     ''' <param name="Operation">Indicates the Action to perform on the controls.</param>
  1278.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1279.     Public Shared Function PerformAction(ByVal ControlCollection As Control.ControlCollection,
  1280.                                          ByVal Operation As [Delegate],
  1281.                                          Optional ByVal ContainsName As String = Nothing) As Boolean
  1282.  
  1283.  
  1284.         Return PerformActionOnControls((From c As Object In ControlCollection), Operation, ContainsName)
  1285.  
  1286.     End Function
  1287.  
  1288. #End Region
  1289.  
  1290. #Region " Asynchronous "
  1291.  
  1292.     ''' <summary>
  1293.     ''' Perform an asynchronous operation on a specific Control.
  1294.     ''' </summary>
  1295.     ''' <param name="Control">Indicates the Control to perform the Action.</param>
  1296.     ''' <param name="Operation">Indicates the Action to perform on the control.</param>
  1297.     Public Shared Function AsyncPerformAction(ByVal Control As Object,
  1298.                                          ByVal Operation As [Delegate])
  1299.  
  1300.         Return AsyncPerformActionOnControls({Control}, Operation)
  1301.  
  1302.     End Function
  1303.  
  1304.     ''' <summary>
  1305.     ''' Perform an asynchronous operation on multiple Controls at once.
  1306.     ''' </summary>
  1307.     ''' <param name="Controls">Indicates the Controls to perform the Action.</param>
  1308.     ''' <param name="Operation">Indicates the Action to perform on the controls.</param>
  1309.     Public Shared Function AsyncPerformAction(ByVal Controls As IEnumerable(Of Object),
  1310.                                               ByVal Operation As [Delegate])
  1311.  
  1312.         Return AsyncPerformActionOnControls(Controls, Operation)
  1313.  
  1314.     End Function
  1315.  
  1316.     ''' <summary>
  1317.     ''' Perform an asynchronous operation on all the Controls of the specified Type on the active Formulary.
  1318.     ''' </summary>
  1319.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1320.     Public Shared Function AsyncPerformAction(Of T)(ByVal Operation As [Delegate],
  1321.                                                     Optional ByVal ContainsName As String = Nothing) As Boolean
  1322.  
  1323.         Return AsyncPerformActionOnControls(Form.ActiveForm.Controls.OfType(Of T), Operation, ContainsName)
  1324.  
  1325.     End Function
  1326.  
  1327.     ''' <summary>
  1328.     ''' Perform an asynchronous operation on all the Controls of the specified Type on the specified Control Container.
  1329.     ''' </summary>
  1330.     ''' <param name="ControlContainer">Indicates the control container where to find the controls.</param>
  1331.     ''' <param name="Operation">Indicates the Action to perform on the controls.</param>
  1332.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1333.     Public Shared Function AsyncPerformAction(Of T)(ByVal ControlContainer As Control,
  1334.                                                     ByVal Operation As [Delegate],
  1335.                                                     Optional ByVal ContainsName As String = Nothing) As Boolean
  1336.  
  1337.  
  1338.         Return AsyncPerformActionOnControls(ControlContainer.Controls.OfType(Of T), Operation, ContainsName)
  1339.  
  1340.     End Function
  1341.  
  1342.     ''' <summary>
  1343.     ''' Perform an asynchronous operation on all the Controls of the specified Type on the specified Control Collection.
  1344.     ''' </summary>
  1345.     ''' <param name="ControlCollection">Indicates the control collection where to find the controls.</param>
  1346.     ''' <param name="Operation">Indicates the Action to perform on the controls.</param>
  1347.     ''' <param name="ContainsName">Indicates that only controls containing name should be collected.</param>
  1348.     Public Shared Function AsyncPerformAction(Of T)(ByVal ControlCollection As Control.ControlCollection,
  1349.                                                     ByVal Operation As [Delegate],
  1350.                                                     Optional ByVal ContainsName As String = Nothing) As Boolean
  1351.  
  1352.         Return AsyncPerformActionOnControls(ControlCollection.OfType(Of T), Operation, ContainsName)
  1353.  
  1354.     End Function
  1355.  
  1356. #End Region
  1357.  
  1358. #End Region
  1359.  
  1360. #End Region
  1361.  
  1362. #Region " Private Methods "
  1363.  
  1364. #Region " Synchronous "
  1365.  
  1366.     ''' <summary>
  1367.     ''' Enable or disable controls.
  1368.     ''' </summary>
  1369.     Private Shared Function EnableOrDisable(ByVal Controls As IEnumerable(Of Object),
  1370.                                             ByVal Enabled As Boolean,
  1371.                                             Optional ByVal ContainsName As String = Nothing) As Boolean
  1372.  
  1373.         If ContainsName IsNot Nothing Then
  1374.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1375.             If Controls.Count = 0 Then Return False
  1376.         End If
  1377.  
  1378.         For Each [control] As Object In Controls
  1379.  
  1380.             If [control].InvokeRequired Then
  1381.                 [control].Invoke(Sub() [control].Enabled = Enabled)
  1382.             Else
  1383.                 [control].Enabled = Enabled
  1384.             End If
  1385.  
  1386.         Next [control]
  1387.  
  1388.         Return True
  1389.  
  1390.     End Function
  1391.  
  1392.     ''' <summary>
  1393.     ''' Show or hide controls.
  1394.     ''' </summary>
  1395.     Private Shared Function ShowOrHide(ByVal Controls As IEnumerable(Of Object),
  1396.                                        ByVal Visible As Boolean,
  1397.                                        Optional ByVal ContainsName As String = Nothing) As Boolean
  1398.  
  1399.         If ContainsName IsNot Nothing Then
  1400.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1401.             If Controls.Count = 0 Then Return False
  1402.         End If
  1403.  
  1404.         For Each [control] As Object In Controls
  1405.  
  1406.             If [control].InvokeRequired Then
  1407.                 [control].Invoke(Sub() [control].Visible = Visible)
  1408.             Else
  1409.                 [control].Visible = Visible
  1410.             End If
  1411.  
  1412.         Next [control]
  1413.  
  1414.         Return True
  1415.  
  1416.     End Function
  1417.  
  1418.     ''' <summary>
  1419.     ''' Check or uncheck controls.
  1420.     ''' </summary>
  1421.     Private Shared Function CheckOrUncheck(ByVal Controls As IEnumerable(Of Object),
  1422.                                            ByVal Checked As Boolean,
  1423.                                            Optional ByVal ContainsName As String = Nothing) As Boolean
  1424.  
  1425.         If ContainsName IsNot Nothing Then
  1426.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1427.             If Controls.Count = 0 Then Return False
  1428.         End If
  1429.  
  1430.         For Each [control] As Object In Controls
  1431.  
  1432.             If [control].InvokeRequired Then
  1433.                 [control].Invoke(Sub() [control].Checked = Checked)
  1434.             Else
  1435.                 [control].Checked = Checked
  1436.             End If
  1437.  
  1438.         Next [control]
  1439.  
  1440.         Return True
  1441.  
  1442.     End Function
  1443.  
  1444.     ''' <summary>
  1445.     ''' Toggle the Enabled state of controls.
  1446.     ''' </summary>
  1447.     Private Shared Function _ToggleEnabled(ByVal Controls As IEnumerable(Of Object),
  1448.                                            Optional ByVal ContainsName As String = Nothing) As Boolean
  1449.  
  1450.         If ContainsName IsNot Nothing Then
  1451.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1452.             If Controls.Count = 0 Then Return False
  1453.         End If
  1454.  
  1455.         For Each [control] As Object In Controls
  1456.  
  1457.             If [control].InvokeRequired Then
  1458.                 [control].Invoke(Sub() [control].Enabled = Not [control].Enabled)
  1459.             Else
  1460.                 [control].Enabled = Not [control].Enabled
  1461.             End If
  1462.  
  1463.         Next [control]
  1464.  
  1465.         Return True
  1466.  
  1467.     End Function
  1468.  
  1469.     ''' <summary>
  1470.     ''' Toggle the Visible state of controls.
  1471.     ''' </summary>
  1472.     Private Shared Function _ToggleVisible(ByVal Controls As IEnumerable(Of Object),
  1473.                                            Optional ByVal ContainsName As String = Nothing) As Boolean
  1474.  
  1475.         If ContainsName IsNot Nothing Then
  1476.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1477.             If Controls.Count = 0 Then Return False
  1478.         End If
  1479.  
  1480.         For Each [control] As Object In Controls
  1481.  
  1482.             If [control].InvokeRequired Then
  1483.                 [control].Invoke(Sub() [control].Visible = Not [control].Visible)
  1484.             Else
  1485.                 [control].Visible = Not [control].Visible
  1486.             End If
  1487.  
  1488.         Next [control]
  1489.  
  1490.         Return True
  1491.  
  1492.     End Function
  1493.  
  1494.     ''' <summary>
  1495.     ''' Toggle the Checked state of controls.
  1496.     ''' </summary>
  1497.     Private Shared Function _ToggleChecked(ByVal Controls As IEnumerable(Of Object),
  1498.                                            Optional ByVal ContainsName As String = Nothing) As Boolean
  1499.  
  1500.         If ContainsName IsNot Nothing Then
  1501.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1502.             If Controls.Count = 0 Then Return False
  1503.         End If
  1504.  
  1505.         For Each [control] As Object In Controls
  1506.  
  1507.             If [control].InvokeRequired Then
  1508.                 [control].Invoke(Sub() [control].Checked = Not [control].Checked)
  1509.             Else
  1510.                 [control].Checked = Not [control].Checked
  1511.             End If
  1512.  
  1513.         Next [control]
  1514.  
  1515.         Return True
  1516.  
  1517.     End Function
  1518.  
  1519.     ''' <summary>
  1520.     ''' Dispose controls.
  1521.     ''' </summary>
  1522.     Private Shared Function DisposeControls(ByVal Controls As IEnumerable(Of Object),
  1523.                                             Optional ByVal ContainsName As String = Nothing) As Boolean
  1524.  
  1525.         If ContainsName IsNot Nothing Then
  1526.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1527.             If Controls.Count = 0 Then Return False
  1528.         End If
  1529.  
  1530.         For Each [control] As Object In Controls
  1531.  
  1532.             If [control].InvokeRequired Then
  1533.                 [control].Invoke(Sub() [control].Dispose())
  1534.             Else
  1535.                 [control].Dispose()
  1536.             End If
  1537.  
  1538.         Next [control]
  1539.  
  1540.         Return True
  1541.  
  1542.     End Function
  1543.  
  1544.     ''' <summary>
  1545.     ''' Perform an operation on Controls.
  1546.     ''' </summary>
  1547.     Private Shared Function PerformActionOnControls(ByVal Controls As IEnumerable(Of Object),
  1548.                                                     ByVal Operation As [Delegate],
  1549.                                                     Optional ByVal ContainsName As String = Nothing) As Boolean
  1550.  
  1551.         If ContainsName IsNot Nothing Then
  1552.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1553.             If Controls.Count = 0 Then Return False
  1554.         End If
  1555.  
  1556.         For Each [Control] As Object In Controls
  1557.  
  1558.             If [Control].InvokeRequired Then
  1559.                 [Control].Invoke(Operation, New Object() {[Control]})
  1560.             Else
  1561.                 Operation.Method.Invoke(Operation, New Object() {[Control]})
  1562.             End If
  1563.  
  1564.         Next [Control]
  1565.  
  1566.         Return True
  1567.  
  1568.     End Function
  1569.  
  1570. #End Region
  1571.  
  1572. #Region " Asynchronous "
  1573.  
  1574.     ''' <summary>
  1575.     ''' Enable or disable controls asynchronouslly.
  1576.     ''' </summary>
  1577.     Private Shared Function AsyncEnableOrDisable(ByVal Controls As IEnumerable(Of Object),
  1578.                                                  ByVal Enabled As Boolean,
  1579.                                                  Optional ByVal ContainsName As String = Nothing)
  1580.  
  1581.         If ContainsName IsNot Nothing Then
  1582.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1583.             If Controls.Count = 0 Then Return False
  1584.         End If
  1585.  
  1586.         For Each [control] As Object In Controls
  1587.  
  1588.             [control].BeginInvoke(Sub() [control].Enabled = Enabled)
  1589.  
  1590.         Next [control]
  1591.  
  1592.         Return True
  1593.  
  1594.     End Function
  1595.  
  1596.     ''' <summary>
  1597.     ''' Show or hide controls asynchronouslly.
  1598.     ''' </summary>
  1599.     Private Shared Function AsyncShowOrHide(ByVal Controls As IEnumerable(Of Object),
  1600.                                             ByVal Visible As Boolean,
  1601.                                             Optional ByVal ContainsName As String = Nothing)
  1602.  
  1603.         If ContainsName IsNot Nothing Then
  1604.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1605.             If Controls.Count = 0 Then Return False
  1606.         End If
  1607.  
  1608.         For Each [control] As Object In Controls
  1609.  
  1610.             [control].BeginInvoke(Sub() [control].Visible = Visible)
  1611.  
  1612.         Next [control]
  1613.  
  1614.         Return True
  1615.  
  1616.     End Function
  1617.  
  1618.     ''' <summary>
  1619.     ''' Check or uncheck controls asynchronouslly.
  1620.     ''' </summary>
  1621.     Private Shared Function AsyncCheckOrUncheck(ByVal Controls As IEnumerable(Of Object),
  1622.                                                 ByVal Checked As Boolean,
  1623.                                                 Optional ByVal ContainsName As String = Nothing)
  1624.  
  1625.         If ContainsName IsNot Nothing Then
  1626.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1627.             If Controls.Count = 0 Then Return False
  1628.         End If
  1629.  
  1630.         For Each [control] As Object In Controls
  1631.  
  1632.             [control].BeginInvoke(Sub() [control].Checked = Checked)
  1633.  
  1634.         Next [control]
  1635.  
  1636.         Return True
  1637.  
  1638.     End Function
  1639.  
  1640.     ''' <summary>
  1641.     ''' Toggle the Enabled state of controls asynchronouslly.
  1642.     ''' </summary>
  1643.     Private Shared Function _AsyncToggleEnabled(ByVal Controls As IEnumerable(Of Object),
  1644.                                                 Optional ByVal ContainsName As String = Nothing)
  1645.  
  1646.         If ContainsName IsNot Nothing Then
  1647.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1648.             If Controls.Count = 0 Then Return False
  1649.         End If
  1650.  
  1651.         For Each [control] As Object In Controls
  1652.  
  1653.             [control].BeginInvoke(Sub() [control].Enabled = Not [control].Enabled)
  1654.  
  1655.         Next [control]
  1656.  
  1657.         Return True
  1658.  
  1659.     End Function
  1660.  
  1661.     ''' <summary>
  1662.     ''' Toggle the Visible state of controls asynchronouslly.
  1663.     ''' </summary>
  1664.     Private Shared Function _AsyncToggleVisible(ByVal Controls As IEnumerable(Of Object),
  1665.                                                 Optional ByVal ContainsName As String = Nothing)
  1666.  
  1667.         If ContainsName IsNot Nothing Then
  1668.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1669.             If Controls.Count = 0 Then Return False
  1670.         End If
  1671.  
  1672.         For Each [control] As Object In Controls
  1673.  
  1674.             [control].BeginInvoke(Sub() [control].Visible = Not [control].Visible)
  1675.  
  1676.         Next [control]
  1677.  
  1678.         Return True
  1679.  
  1680.     End Function
  1681.  
  1682.     ''' <summary>
  1683.     ''' Toggle the Checked state of controls asynchronouslly.
  1684.     ''' </summary>
  1685.     Private Shared Function _AsyncToggleChecked(ByVal Controls As IEnumerable(Of Object),
  1686.                                                 Optional ByVal ContainsName As String = Nothing)
  1687.  
  1688.         If ContainsName IsNot Nothing Then
  1689.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1690.             If Controls.Count = 0 Then Return False
  1691.         End If
  1692.  
  1693.         For Each [control] As Object In Controls
  1694.  
  1695.             [control].BeginInvoke(Sub() [control].Checked = Not [control].Checked)
  1696.  
  1697.         Next [control]
  1698.  
  1699.         Return True
  1700.  
  1701.     End Function
  1702.  
  1703.     ''' <summary>
  1704.     ''' Dispose controls asynchronouslly.
  1705.     ''' </summary>
  1706.     Private Shared Function AsyncDisposeControls(ByVal Controls As IEnumerable(Of Object),
  1707.                                                  Optional ByVal ContainsName As String = Nothing)
  1708.  
  1709.         If ContainsName IsNot Nothing Then
  1710.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1711.             If Controls.Count = 0 Then Return False
  1712.         End If
  1713.  
  1714.         For Each [control] As Object In Controls
  1715.  
  1716.             [control].BeginInvoke(Sub() [control].Dispose())
  1717.  
  1718.         Next [control]
  1719.  
  1720.         Return True
  1721.  
  1722.     End Function
  1723.  
  1724.     ''' <summary>
  1725.     ''' Perform an asynchronous operation on Controls.
  1726.     ''' </summary>
  1727.     Private Shared Function AsyncPerformActionOnControls(ByVal Controls As IEnumerable(Of Object),
  1728.                                                          ByVal Operation As [Delegate],
  1729.                                                          Optional ByVal ContainsName As String = Nothing)
  1730.  
  1731.         If ContainsName IsNot Nothing Then
  1732.             Controls = Controls.Where(Function(ctrl) ctrl.name.contains(ContainsName))
  1733.             If Controls.Count = 0 Then Return False
  1734.         End If
  1735.  
  1736.         For Each [Control] As Object In Controls
  1737.  
  1738.             If [Control].InvokeRequired Then
  1739.                 [Control].BeginInvoke(Operation, New Object() {[Control]})
  1740.             Else
  1741.                 [Control].BeginInvoke(Operation.Method.Invoke(Operation, New Object() {[Control]}))
  1742.             End If
  1743.  
  1744.         Next [Control]
  1745.  
  1746.         Return True
  1747.  
  1748.     End Function
  1749.  
  1750. #End Region
  1751.  
  1752. #End Region
  1753.  
  1754. End Class
  1755.  
  1756. #End Region
RAW Paste Data