Advertisement
Guest User

[VB.NET] Control Iterator by ElektroStudios

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