Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取组件及其类型的属性_C#_Winforms - Fatal编程技术网

C# 获取组件及其类型的属性

C# 获取组件及其类型的属性,c#,winforms,C#,Winforms,这是我的代码,显示标签组件的所有属性: var t = c.GetType(); // c is a Label var controls = t.GetProperties(); PropertyInfo[] propertyInfo = t.GetProperties(); 我使用的是PropertyGrid,我只想显示标签类型为image(image02)的属性。这可能吗?那么您希望像Visual Studio一样显示propertygrid,但不是使用属性的值,而是使用该属性接受的

这是我的代码,显示标签组件的所有属性:

var t = c.GetType(); // c is a Label
var controls = t.GetProperties();
PropertyInfo[] propertyInfo =   t.GetProperties();

我使用的是PropertyGrid,我只想显示标签类型为image(image02)的属性。这可能吗?

那么您希望像Visual Studio一样显示propertygrid,但不是使用属性的值,而是使用该属性接受的数据类型?你想在imageform中这样做吗?这就是你要问的吗?你不能用一个包含两列的表以普通形式显示它?我想在PropertyGrid中显示,即使在image02中也可以,也就是说,属性和该属性的类型(字符串、布尔…)就像在visual studio中一样。我认为使用
PropertyGrid
是不可能的。还有其他选项:您可以创建自己的
PropertyGridWithTypes
(可以是一个简单的
DataGridView
,有3列),也可以在其他地方显示类型(在描述窗格中显示类型或将类型显示为值的一部分相对容易:为每个属性提供
TypeConverter
,它将生成包含值和类型的文本,而在转换回类型时,类型应该是可选的)。