私はICustomTypeDescriptorを実装するクラス(コントロール)を持っています。これは、カスタマイズのために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#でデザイン時のフラグのためのアナログはありますか?条件付きコンパイルを使用する方が良いでしょうか?
あなたはwpfまたはwinformについて話していますか? –
* [Visual Studioデザイナーが.NETコードを実行しているかどうかを確認する方法](http://stackoverflow.com/questions/73515/how-to-tell-if-net-code-is-being-ビジュアルスタジオデザイナー)*。 –