C# 根据控件NAME名字 操作控件

秀啊!

现在知道一个字符串“label1”
想根据这个“label1”操作窗体内 label1控件的TEXT值

答案:

string name = "label1";
object o = this.GetType().GetField(name, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase).GetValue(this);
((Label)o).Text = "hello world!";

 

转载:https://blog.csdn.net/pencher_liu/article/details/82462356

posted @ 2020-12-09 14:43  我得想个好名字  阅读(1370)  评论(0)    收藏  举报