Iterate text fields by name, inside a tab control

I have a bunch of text fields, more precisely 150. They are located inside different tabs of the tab control and are not ordered by name on the screen. They are called simply textBox1, textBox2, textBox3 ... I would like to be able to repeat them in order by name, and not by how they appear on the form. How should I do it?

+3
source share
1 answer
public IEnumerable<Control> GetChildrenRecursive(Control parent)
{
    var controls = new List<Control>();
    foreach(Control child in parent.Controls)
        controls.AddRange(GetChildrenRecursive(child));
    controls.Add(parent); //fix
    return controls;
}

TextBox[] textboxes = GetChildrenRecursive(this)
       .OfType<TextBox>().OrderBy(i => i.Name).ToArray();
+5
source

Source: https://habr.com/ru/post/1754608/


All Articles