In GUI programming, specific controls are often required. In C#, the method provides a solution to retrieve control according to the name.
Suppose you have a Control.ControlCollection.Find
called "MyMenu" in a complex window layout. To access this control directly, it usually quotes it as:
ToolStripMenuItem
However, when the control is dynamically generated from the external source (such as the XML file), it becomes difficult to use this method to directly access them.
this.myMenu...
method of the
object, as shown below:
Control.ControlCollection
Find()
Replace "name" with the dynamic name of the control you want to access. This method returns a control array containing the matching name, allowing you to further operate or interact the control required.
The above is the detailed content of How Can I Find a Windows Forms Control by Name in C#?. For more information, please follow other related articles on the PHP Chinese website!