请教怎么获取 winform中 Properties 窗口的属性值
请问如何获取 winform中 Properties 窗口的属性值?
单单获取那里的所有成员的值,是如何获取的?
------解决思路----------------------
如果问的是 app.config中的配置项
------解决思路----------------------
使用PropertyGrid控件绑定对象,或者自己用反射遍历属性获取值。
------解决思路----------------------
反射遍历winform对象的所有属性
如:
------解决思路----------------------
你不会判断一下,如果类型是窗体,就获取,如果是别的,就不获取吗
------解决思路----------------------
你不会判断下吗?反射后判断PropertyInfo的Browseable的特性为true的则是properties窗口的属性
------解决思路----------------------
单单获取那里的所有成员的值,是如何获取的?
------解决思路----------------------
如果问的是 app.config中的配置项
string server = Properties.Settings.Default.Server; //Server是配置项的属性名称
------解决思路----------------------
使用PropertyGrid控件绑定对象,或者自己用反射遍历属性获取值。
------解决思路----------------------
反射遍历winform对象的所有属性
如:
Form1 aa = new Form1();
Type type = aa.GetType();//获取类型
System.Reflection.PropertyInfo []propertyInfos = type. GetProperties();
foreach(System.Reflection.PropertyInfo propertyInfo in propertyInfos)
{
propertyInfo.SetValue(aa, 5, null);//给对应属性赋值
int value = (int)propertyInfo.GetValue(aa, null);
Console.WriteLine(value );
}
------解决思路----------------------
你不会判断一下,如果类型是窗体,就获取,如果是别的,就不获取吗
------解决思路----------------------
你不会判断下吗?反射后判断PropertyInfo的Browseable的特性为true的则是properties窗口的属性
------解决思路----------------------
你写的需求在哪儿?
7楼,哥们.
你不会判断下吗?反射后判断PropertyInfo的Browseable的特性为true的则是properties窗口的属性
问题是不会这么用....网上搜的都没有...可以粘上代码么...thanks...
Form1 aa = new Form1();
Type type = aa.GetType();//获取类型
System.Reflection.PropertyInfo []propertyInfos = type. GetProperties();
foreach(System.Reflection.PropertyInfo propertyInfo in propertyInfos)
{
//propertyInfo.SetValue(aa, 5, null);//给对应属性赋值
//int value = (int)propertyInfo.GetValue(aa, null);
object []attributes = property.GetCustomAttributes(typeof(BrowserableAttribute), true);
if(attributes.Length>0)
{
Console.WriteLine("在属性窗口里能看到" );
}
}