Im looking for a way to group a number of controls in Winforms by name using C#.
The best way I can describe the functionality I need is to compare it to how classes work in HTML/CSS where the same class is recycled throughout to target only the controls that are associated with that class.
I have tried using the name property from Control.Name but this hasnt worked out as planned.
Example
//Group controls by a group identifier in this case the string 'name'`
txtForename.name = "name";
txtSurname.name = "name";
txtNotAName.name = "notAName";
foreach (Control control in form.Controls)
{
if (control.Name == "name")
{
Console.WriteLine("true");
}
}
Expected output
true;
true;
If more than one control has the same name, can I target them while searching a collection of controls?
Is this even possible?