Finding the control in the Windows window is a convenient way to access a specific element in the access window. This is especially useful when dealing with a large number of controls or automation tasks.
Solution:
To find the control control according to the name, please use the method. This method uses a string parameter to indicate the name of the control to be found.
Control.ControlCollection.Find
In this example, we searched the control named "Textbox1" in the
<code class="language-C#">TextBox tbx = this.Controls.Find("textBox1", true).FirstOrDefault() as TextBox;</code>
variables. Controls
TextBox
Other usage: tbx
The method can also be used for control array:
This allows you to find multiple controls according to the name and perform operations on it.
Find
Note:
<code class="language-C#">Control[] tbxs = this.Controls.Find(txtbox_and_message[0,0], true);</code>
Make sure your designated control name is unique in the window. Otherwise, may return an arbitrary control with a specified name.
The above is the detailed content of How Can I Locate Windows Forms Controls by Name?. For more information, please follow other related articles on the PHP Chinese website!