且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

查找Windows窗体的名字控制

更新时间:2023-12-06 11:07:28

您可以使用窗体的的 Controls.Find()方法来检索参考后面:

You can use the form's Controls.Find() method to retrieve a reference back:

        var matches = this.Controls.Find("button2", true);

要注意的是这个返回的阵列的,控件的名称属性可以是模糊的,没有机制可确保控件具有唯一的名称。你必须强制自己。

Beware that this returns an array, the Name property of a control can be ambiguous, there is no mechanism that ensures that a control has a unique name. You'll have to enforce that yourself.