Advertisement
Guest User

Control Iterator for VB.Net (15-Sep-2014)

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