码迷,mamicode.com
首页 > 其他好文 > 详细

控件名称获取与设置

时间:2016-09-17 21:45:58      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

private void button6_Click(object sender, EventArgs e)
{
  this.listBox1.Items.Clear();

  FieldInfo[] FieldInfos = this.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);

  foreach (FieldInfo theFieldInfo in FieldInfos)
  {
    PropertyInfo thePropertyInfo = theFieldInfo.FieldType.GetProperty("Text");

    if (thePropertyInfo == null) continue;

    string ctrlName = theFieldInfo.Name;
    string className = theFieldInfo.FieldType.ToString();
    string oldValue = thePropertyInfo.GetValue(theFieldInfo.GetValue(this), null).ToString();
    string newValue = "昆山";


    string Line1 = string.Format("类名={0} \t控件名称={1}", className, ctrlName);
    string Line2 = string.Format("老值={0} \t新值={1}", oldValue, newValue);
    this.listBox1.Items.Add("");
    this.listBox1.Items.Add(Line1);
    this.listBox1.Items.Add(Line2);

    thePropertyInfo.SetValue(theFieldInfo.GetValue(this), "玉", null);
  }
}

控件名称获取与设置

标签:

原文地址:http://www.cnblogs.com/LongHuaiYu/p/5879626.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!