日期:2014-05-18  浏览次数:21036 次

通过属性字符串访问控件的属性值
窗体上自己定义的控件,通过for 循环读取
自己定义的控件有appName属性
但是form.controls[i] 没有这个属性。目前通过
 Type t = form.controls[i].GetType();

  PropertyInfo p = t.GetProperty("appFieldName", typeof(string));
  cwfTextBox1.Text = p.GetValue(cwfTextBox1, null).ToString();
读取的,有没好的办法!?

------解决方案--------------------
foreach(Control con in form.Controls)
{
cwfTextBox txt=con as cwfTextBox();//假设cwfTextBox是你的控件
if(txt!=null)
{
string s=txt.appName;
}
}
看看这样行不
------解决方案--------------------
for(int i=0 ;i< form.control.count;i++)
{
if(from.controls[i].name == 你空间的名字)
{
string name = 你的控件.appName;
}

}

这样应该可以的。