且构网

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

如何使用字符串变量 -c# 获取标签名称

更新时间:2023-11-15 12:00:58

您必须从给定名称的表单控件列表中找到 Label 控件.

You have to find Label Control from the list of form control for a given name.

var control = this.Controls.OfType<Label>()
                           .FirstOrDefault(c=>c.Name == labelName");

if(control != null)
{
    // Now you can play with your logic.
    control.Invoke((MethodInvoker)(() => control.Text = displayValue.ToString())); 
}