I have a list of my textbox names, and I want to find a control by name. How is it possible?
Control c = TheForm("Form1"); Once we have this, we can gain access to ALL the child controls including the children in other container controls on the form. The next method to declare is the one that locates the control to access on the form returned by the TheForm method.
Windows Forms controls are reusable components that encapsulate user interface functionality and are used in client-side, Windows-based applications. Not only does Windows Forms provide many ready-to-use controls, it also provides the infrastructure for developing your own controls.
A control's "control name" is given by its name attribute. The scope of the name attribute for a control within a FORM element is the FORM element. Each control has both an initial value and a current value, both of which are character strings.
The Name property can be used at run time to evaluate the object by name rather than type and programmatic name. Because the Name property returns a String type, it can be evaluated in case-style logic statements ( Select statement in Visual Basic, switch statement in Visual C# and Visual C++).
Use Control.ControlCollection.Find.
TextBox tbx = this.Controls.Find("textBox1", true).FirstOrDefault() as TextBox; tbx.Text = "found!";
EDIT for asker:
Control[] tbxs = this.Controls.Find(txtbox_and_message[0,0], true); if (tbxs != null && tbxs.Length > 0) { tbxs[0].Text = "Found!"; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With