Use foreach for form button controls

Sergio23 271 Reputation points
2021-07-05T13:46:18.267+00:00

To list all TextBoxes, do I need to list all controls?
Example
foreach (Control InitCtrl in this.Controls)

Can you be more specific?
Example
foreach (TextBox TxtBx in ?????)

Can it be done?
How?
Thanks

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,008 questions
No comments
{count} votes

Accepted answer
  1. Castorix31 65,791 Reputation points
    2021-07-05T14:03:26.633+00:00

    For example :

                    foreach (TextBox txtBox in this.Controls.OfType<TextBox>())
                    {
                        // code
                    }
    
    No comments

0 additional answers

Sort by: Most helpful