【发布时间】:2021-07-06 03:57:31
【问题描述】:
我是 C# 新手,我知道如何动态添加控件,但我不知道如何将该控件设置为 this.[control_name]。请注意,这里的this 是Form。
这可以使用private System.Windows.Forms.[Control_type] [control-name]; 静态完成,但我将如何通过方法执行此操作,以便稍后声明this.[control-name] = [variable]?
请注意,variable 类似于 new TextBox();
【问题讨论】:
-
我这样做是因为我需要能够从创建控件的另一个范围引用该控件。所以我会使用
this.[control-name],因为这在所有范围内都是通用的。 -
你不能这样做,因为代码不会编译
-
您可以拥有一个以名称为键的控件字典
-
@stuartd 那么我会使用
Form.Controls.Find([dict],true)[0],我假设?
标签: c# visual-studio winforms controls desktop