DesignOnlyAttribute クラス
アセンブリ: System (system.dll 内)

<AttributeUsageAttribute(AttributeTargets.All)> _ Public NotInheritable Class DesignOnlyAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets::All)] public ref class DesignOnlyAttribute sealed : public Attribute

DesignOnlyAttribute に true を設定してマークされているメンバは、デザイン時にだけ設定できます。通常、これらのプロパティはデザイン時しか存在せず、実行時にオブジェクト上に存在するプロパティには対応しません。
属性を持たないメンバ、または DesignOnlyAttribute を false に設定してマークされているメンバは、実行時に設定できます。既定値は false です。
DesignOnlyAttribute が true に設定されているプロパティは、値が InitializeComponent メソッドではなく .resx ファイルにシリアル化されます。

GetLanguage プロパティを作成する例を次に示します。このプロパティは、DesignOnlyAttribute でマークされます。
<DesignOnly(True)> _ Public Property GetLanguage() As CultureInfo Get ' Insert code here. Return myCultureInfo End Get Set ' Insert code here. End Set End Property
[DesignOnly(true)] public CultureInfo GetLanguage { get { // Insert code here. return myCultureInfo; } set { // Insert code here. } }
public: [DesignOnly(true)] property CultureInfo^ GetLanguage { CultureInfo^ get() { // Insert code here. return myCultureInfo; } void set( CultureInfo^ value ) { // Insert code here. } }
/** @attribute DesignOnly(true) */ /** @property */ public CultureInfo get_GetLanguage() { // Insert code here. return myCultureInfo; } //get_GetLanguage /** @property */ public void set_GetLanguage(CultureInfo value) { // Insert code here. } //set_GetLanguage
DesignOnlyAttribute の値を取得する例を次に示します。最初に、オブジェクトのすべてのプロパティを保持する PropertyDescriptorCollection を取得します。次に、インデックスを付けて PropertyDescriptorCollection から GetLanguage プロパティを検索します。そして、このプロパティの属性を返し、その属性を属性変数に保存します。
最後に、AttributeCollection から DesignOnlyAttribute を取得し、取得した情報をコンソール画面に書き込むことによって、プロパティを設定できるのがデザイン時だけかどうかを出力します。
' Gets the attributes for the property. Dim attributes As AttributeCollection = _ TypeDescriptor.GetProperties(Me)("GetLanguage").Attributes ' Prints the description by retrieving the DescriptionAttribute ' from the AttributeCollection. Dim myAttribute As DesignOnlyAttribute = _ CType(attributes(GetType(DesignOnlyAttribute)), DesignOnlyAttribute) Console.WriteLine(("This property is design only :" & _ myAttribute.IsDesignOnly.ToString()))
// Gets the attributes for the property. AttributeCollection attributes = TypeDescriptor.GetProperties(this)["GetLanguage"].Attributes; /* Prints the description by retrieving the DescriptionAttribute * from the AttributeCollection. */ DesignOnlyAttribute myAttribute = (DesignOnlyAttribute)attributes[typeof(DesignOnlyAttribute)]; Console.WriteLine("This property is design only :" + myAttribute.IsDesignOnly.ToString());
// Gets the attributes for the property. AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "GetLanguage" ]->Attributes; /* Prints the description by retrieving the DescriptionAttribute * from the AttributeCollection. */ DesignOnlyAttribute^ myAttribute = dynamic_cast<DesignOnlyAttribute^>(attributes[ DesignOnlyAttribute::typeid ]); Console::WriteLine( "This property is design only :{0}", myAttribute->IsDesignOnly );
// Gets the attributes for the property. AttributeCollection attributes = TypeDescriptor.GetProperties(this). get_Item("GetLanguage").get_Attributes(); /* Prints the description by retrieving the DescriptionAttribute from the AttributeCollection. */ DesignOnlyAttribute myAttribute = (DesignOnlyAttribute)(attributes. get_Item(DesignOnlyAttribute.class.ToType())); Console.WriteLine("This property is design only :" + System.Convert.ToString(myAttribute.get_IsDesignOnly()));

System.Attribute
System.ComponentModel.DesignOnlyAttribute


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DesignOnlyAttribute クラスのページへのリンク