C# 如何最好地引用此控件?

C# 如何最好地引用此控件?,c#,winforms,C#,Winforms,我有一个TableLayoutPanel,我正在使用下面的语法向其中添加控件 tableLayoutPanelTableHeaders.Controls.Add(new Label {Name = "myLabel, "Text = "+", Font = new Font("Microsoft Sans Serif", 14, FontStyle.Bold), ForeColor = System.Drawing.Color.ForestGreen, AutoSize = true, Enab

我有一个TableLayoutPanel,我正在使用下面的语法向其中添加控件

tableLayoutPanelTableHeaders.Controls.Add(new Label {Name = "myLabel, "Text = "+", Font = new Font("Microsoft Sans Serif", 14, FontStyle.Bold), ForeColor = System.Drawing.Color.ForestGreen, AutoSize = true, Enabled = false}, 3, 1);
有没有什么方法可以让我引用我正在创建的标签,而不必先搜索它?目前,我必须在TableLayoutPanel的子控件中搜索一个名为“myLabel”的控件


我知道我可以先创建标签并将其分配给下面这样的变量,然后将其添加到组合框中,但我喜欢上面的代码将所有内容保持在一行上

Label myLabel = new Label {Name = "myLabel, "Text = "+", Font = new Font("Microsoft Sans Serif", 14, FontStyle.Bold), ForeColor = System.Drawing.Color.ForestGreen, AutoSize = true, Enabled = false};

还有,有人知道我在第一个例子中创建的控件是否被一个特殊的术语所引用吗

“上面的代码将所有内容保持在一行”-以可读性为代价。并在以后尝试访问label实例时给您带来麻烦。“首先创建标签并将其分配给变量”听起来像是一个更好的主意
(标签)tableLayouPanel1.Controls[“label1”]
tableLayouPanel1.Controls.Find(“label1”,true).OfType().FirstOrDefault()
如果标签在容器内多层嵌套。@如果有多个同名控件,这只是对不知道可以使用
控件
索引器或不知道有
Find
方法在多层嵌套中查找控件的人的注释。也许不是一个完美的例子,但足够好的指向这些属性/方法的指针。无论如何,花很多时间讨论这件事并不重要;)谢谢大家,我最终按照ASh的建议将我的控件分配给了变量。另外,我也不知道。控制系统有一个索引器。很好的一个@Reza Aghaei。
Label myLabel = new Label {Name = "myLabel, "Text = "+", Font = new Font("Microsoft Sans Serif", 14, FontStyle.Bold), ForeColor = System.Drawing.Color.ForestGreen, AutoSize = true, Enabled = false};