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

<AttributeUsageAttribute(AttributeTargets.Method Or AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Event)> _ Public NotInheritable Class DesignerSerializationVisibilityAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Event)] public sealed class DesignerSerializationVisibilityAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method|AttributeTargets::Property|AttributeTargets::Field|AttributeTargets::Event)] public ref class DesignerSerializationVisibilityAttribute sealed : public Attribute

シリアライザでデザイン モード ドキュメントの永続化状態を設定する場合に、デザイン時に設定されたプロパティの値を永続化するために、コンポーネントの初期化メソッドにコードを追加することがよくあります。他の動作を指示する属性が設定されていなければ、ほとんどの基本的な型に対して、既定でこれが行われます。
DesignerSerializationVisibilityAttribute を使用すると、プロパティの値を Visible として初期化コードで永続化するのか、Hidden として初期化コードで永続化しないのか、または Content として、そのプロパティに代入するオブジェクトのパブリックな、隠ぺいされていない各プロパティに対して初期化コードを生成する必要があるのかを示すことができます。
DesignerSerializationVisibilityAttribute のないメンバは、値が Visible の DesignerSerializationVisibilityAttribute を持つものとして扱われます。Visible としてマークされたプロパティの値は、可能であれば、その型のシリアライザでシリアル化されます。特定の型やプロパティに対してカスタムのシリアル化を指定するには、DesignerSerializerAttribute を使用します。

Content に設定された DesignerSerializationVisibilityAttribute の使用方法を次のコード例に示します。この例では、デザイン時に構成できる、ユーザー コントロールのパブリック プロパティの値を永続化します。この例を使用するには、最初に次のコードをコンパイルして、ユーザー コントロール ライブラリを作成します。次に、新しい Windows アプリケーション プロジェクトで、コンパイルされた .dll ファイルへの参照を追加します。Visual Studio を使用している場合は、ContentSerializationExampleControl が自動的に ツールボックス に追加されます。
ツールボックス からコントロールをフォームにドラッグし、[プロパティ] ウィンドウの一覧に示されている DimensionData オブジェクトのプロパティを設定します。フォームのコードを表示すると、コードが親フォームの InitializeComponent メソッドに追加されています。このコードは、コントロールのプロパティの値を、デザイン モードで設定した値に設定します。
Imports System Imports System.Collections Imports System.ComponentModel Imports System.ComponentModel.Design Imports System.Drawing Imports System.Windows.Forms Namespace DesignerSerializationVisibilityTest _ ' The code for this user control declares a public property of type DimensionData with a DesignerSerializationVisibility ' attribute set to DesignerSerializationVisibility.Content, indicating that the properties of the object should be serialized. ' The public, not hidden properties of the object that are set at design time will be persisted in the initialization code ' for the class object. Content persistence will not work for structs without a custom TypeConverter. Public Class ContentSerializationExampleControl Inherits System.Windows.Forms.UserControl Private components As System.ComponentModel.Container = Nothing <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _ Public ReadOnly Property Dimensions() As DimensionData Get Return New DimensionData(Me) End Get End Property Public Sub New() InitializeComponent() End Sub 'New Protected Overloads Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Dispose Private Sub InitializeComponent() End Sub 'InitializeComponent End Class 'ContentSerializationExampleControl ' This attribute indicates that the public properties of this object should be listed in the property grid. <TypeConverterAttribute(GetType(System.ComponentModel.ExpandableObjectConverter))> _ Public Class DimensionData Private owner As Control ' This class reads and writes the Location and Size properties from the Control which it is initialized to. Friend Sub New(ByVal owner As Control) Me.owner = owner End Sub 'New Public Property Location() As Point Get Return owner.Location End Get Set(ByVal Value As Point) owner.Location = Value End Set End Property Public Property FormSize() As Size Get Return owner.Size End Get Set(ByVal Value As Size) owner.Size = Value End Set End Property End Class 'DimensionData End Namespace 'DesignerSerializationVisibilityTest
using System; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing; using System.Windows.Forms; namespace DesignerSerializationVisibilityTest { // The code for this user control declares a public property of type DimensionData with a DesignerSerializationVisibility // attribute set to DesignerSerializationVisibility.Content, indicating that the properties of the object should be serialized. // The public, not hidden properties of the object that are set at design time will be persisted in the initialization code // for the class object. Content persistence will not work for structs without a custom TypeConverter. public class ContentSerializationExampleControl : System.Windows.Forms.UserControl { private System.ComponentModel.Container components = null; [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public DimensionData Dimensions { get { return new DimensionData(this); } } public ContentSerializationExampleControl() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if( components != null ) components.Dispose(); } base.Dispose( disposing ); } private void InitializeComponent() { components = new System.ComponentModel.Container(); } } [TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))] // This attribute indicates that the public properties of this object should be listed in the property grid. public class DimensionData { private Control owner; // This class reads and writes the Location and Size properties from the Control which it is initialized to. internal DimensionData(Control owner) { this.owner = owner; } public Point Location { get { return owner.Location; } set { owner.Location = value; } } public Size FormSize { get { return owner.Size; } set { owner.Size = value; } } } }
#using <System.Windows.Forms.dll> #using <System.Drawing.dll> #using <System.dll> using namespace System; using namespace System::Collections; using namespace System::ComponentModel; using namespace System::ComponentModel::Design; using namespace System::Drawing; using namespace System::Windows::Forms; // This attribute indicates that the public properties of this object should be listed in the property grid. [TypeConverterAttribute(System::ComponentModel::ExpandableObjectConverter::typeid)] public ref class DimensionData { private: Control^ owner; internal: // This class reads and writes the Location and Size properties from the Control which it is initialized to. DimensionData( Control^ owner ) { this->owner = owner; } public: property Point Location { Point get() { return owner->Location; } void set( Point value ) { owner->Location = value; } } property Size FormSize { Size get() { return owner->Size; } void set( Size value ) { owner->Size = value; } } }; // The code for this user control declares a public property of type DimensionData with a DesignerSerializationVisibility // attribute set to DesignerSerializationVisibility.Content, indicating that the properties of the object should be serialized. // The public, not hidden properties of the object that are set at design time will be persisted in the initialization code // for the class object. Content persistence will not work for structs without a custom TypeConverter. public ref class ContentSerializationExampleControl: public System::Windows::Forms::UserControl { private: System::ComponentModel::Container^ components; public: property DimensionData^ Dimensions { [DesignerSerializationVisibility(DesignerSerializationVisibility::Content)] DimensionData^ get() { return gcnew DimensionData( this ); } } ContentSerializationExampleControl() { InitializeComponent(); } public: ~ContentSerializationExampleControl() { if ( components != nullptr ) { delete components; } } private: void InitializeComponent() { components = gcnew System::ComponentModel::Container; } };
package DesignerSerializationVisibilityTest; import System.*; import System.Collections.*; import System.ComponentModel.*; import System.ComponentModel.Design.*; import System.Drawing.*; import System.Windows.Forms.*; // The code for this user control declares a public property of type // DimensionData with a DesignerSerializationVisibility attribute set // to DesignerSerializationVisibility.Content, indicating that the properties // of the object should be serialized. // The public, not hidden properties of the object that are set at design // time will be persisted in the initialization code for the class object. // Content persistence will not work for structs without a custom // TypeConverter. public class ContentSerializationExampleControl extends System.Windows.Forms.UserControl { private System.ComponentModel.Container components = null; /** @attribute DesignerSerializationVisibility( DesignerSerializationVisibility.Content) */ /** @property */ public DimensionData get_Dimensions() { return new DimensionData(this); } //get_Dimensions public ContentSerializationExampleControl() { InitializeComponent(); } //ContentSerializationExampleControl protected void Dispose(boolean disposing) { if (disposing) { if (components != null) { components.Dispose(); } } super.Dispose(disposing); } //Dispose private void InitializeComponent() { components = new System.ComponentModel.Container(); } //InitializeComponent } //ContentSerializationExampleControl /** @attribute TypeConverterAttribute(System.ComponentModel. ExpandableObjectConverter.class) */ public class DimensionData { // This attribute indicates that the public properties of this // object should be listed in the property grid. private Control owner; // This class reads and writes the Location and Size properties // from the Control which it is initialized to. DimensionData(Control owner) { this.owner = owner; } //DimensionData /** @property */ public Point get_Location() { return owner.get_Location(); } //get_Location /** @property */ public void set_Location(Point value) { owner.set_Location(value); } //set_Location /** @property */ public Size get_FormSize() { return owner.get_Size(); } //get_FormSize /** @property */ public void set_FormSize(Size value) { owner.set_Size(value); } //set_FormSize } //DimensionData

System.Attribute
System.ComponentModel.DesignerSerializationVisibilityAttribute


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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