In the Windows window application, positioning specific controls according to the name requires a system. An effective method is to use the
method in the class. Control.ControlCollection
Find
For example, assuming that you maintain a list of text box names, you need to find a specific text box according to the specified name. Using the Method, you can efficiently locate the control.
The grammar of the method is as follows: Find
Among them:
Find
<code class="language-csharp">public Control[] Find(string key, bool searchAllChildren)</code>
: A Boolean value, indicate whether the sub -control is included in the search.
key
searchAllChildren
and set its text to "Find!".
<code class="language-csharp">TextBox tbx = this.Controls.Find("textBox1", true).FirstOrDefault() as TextBox; tbx.Text = "找到!";</code>
The above is the detailed content of How Can I Efficiently Find Specific Controls by Name in Windows Forms?. For more information, please follow other related articles on the PHP Chinese website!