我有一个实现了ICustomTypeDescriptor接口的类(control),用于在设计时和运行时通过PropertyGrid进行自定义。我需要在设计时公开不同的属性(像width
,height
等标准控件属性),在程序中使用PropertyGrid更改该控件的其他属性时则公开不同的属性。
我的代码如下:
class MyControl : UserControl, ICustomTypeDescriptor
{
//Some code..
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
return GetProperties();
}
public PropertyDescriptorCollection GetProperties()
{
//I need to do something like this:
if (designTime)
{ //Expose standart controls properties
return TypeDescriptor.GetProperties(this, true);
}
else
{
//Forming a custom property descriptor collection
PropertyDescriptorCollection pdc = new PropertyDescriptorCollection(null);
//Some code..
return pdc;
}
}
}
在C#中是否有类似于设计时标志的模拟器? 在条件编译方面是否更好?