控件名称获取与设置
Posted LongHuaiYu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了控件名称获取与设置相关的知识,希望对你有一定的参考价值。
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);
}
}
以上是关于控件名称获取与设置的主要内容,如果未能解决你的问题,请参考以下文章
如何在 C# Winforms 的下拉列表控件中获取数据源名称