DesignerSerializationVisibilityAttribute DesignerSerializationVisibilityAttribute DesignerSerializationVisibilityAttribute DesignerSerializationVisibilityAttribute Class

定義

デザイン時にコンポーネントのプロパティをシリアル化するときに使用する永続化の種類を指定します。Specifies the type of persistence to use when serializing a property on a component at design time.

public ref class DesignerSerializationVisibilityAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Method | System.AttributeTargets.Property)]
[System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property)]
[System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Event)]
public sealed class DesignerSerializationVisibilityAttribute : Attribute
type DesignerSerializationVisibilityAttribute = class
    inherit Attribute
Public NotInheritable Class DesignerSerializationVisibilityAttribute
Inherits Attribute
継承
DesignerSerializationVisibilityAttributeDesignerSerializationVisibilityAttributeDesignerSerializationVisibilityAttributeDesignerSerializationVisibilityAttribute
属性

次のコード例は、の使用を示します、DesignerSerializationVisibilityAttribute設定Contentします。The following code example demonstrates the use of a DesignerSerializationVisibilityAttribute set to Content. デザイン時に構成できるユーザー コントロールのパブリック プロパティの値を保持します。It persists the values of a public property of a user control, which can be configured at design time. 例を使用するには、ユーザー コントロール ライブラリに最初に、次のコードをコンパイルします。To use the example, first compile the following code into a user control library. 次に、新しい Windows アプリケーション プロジェクトでコンパイルされた .dll ファイルへの参照を追加します。Next, add a reference to the compiled .dll file in a new Windows Application project. Visual Studio を使用している場合、ContentSerializationExampleControlが自動的に追加、ツールボックスします。If you are using Visual Studio, the ContentSerializationExampleControl is automatically added to the Toolbox.

コントロールをドラッグ、ツールボックス、フォームのプロパティを設定し、DimensionDataオブジェクトがプロパティ ウィンドウに表示します。Drag the control from the Toolbox to a form, and set the properties of the DimensionData object listed in the Properties window. フォームのコードを表示するときにコードに追加されている、InitializeComponent親フォームのメソッド。When you view the code for the form, code will have been added to the InitializeComponent method of the parent form. このコードは、デザイン モードに設定したものに、コントロールのプロパティの値を設定します。This code sets the values of the control's properties to those which you have set in design mode.

#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;
   }
};
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;
	    }
	}
    }
}
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 (components IsNot 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

注釈

シリアライザーがデザイン モードのドキュメントの永続化状態が解決しない場合に多くの場合、デザイン時に設定されているプロパティの値を保持するコンポーネントの初期化メソッドにコードを追加します。When a serializer persists the persistable state of a design mode document, it often adds code to the initialization method of components to persist values of properties that have been set at design time. これは、その他の動作を指示する属性が設定されていない場合の最も基本的な種類は、既定で。This happens by default for most basic types, if no attribute has been set to direct other behavior.

DesignerSerializationVisibilityAttribute、プロパティの値があるかどうかを示すVisible、初期化コードを保存するか、 Hidden、初期化コードで永続化しないとから成るContent、する必要があります。プロパティに割り当てられているオブジェクトの各パブリックな非プロパティに対して生成されたコードを初期化します。With the DesignerSerializationVisibilityAttribute, you can indicate whether the value for a property is Visible, and should be persisted in initialization code, Hidden, and should not be persisted in initialization code, or consists of Content, which should have initialization code generated for each public, not hidden property of the object assigned to the property.

メンバーがない、DesignerSerializationVisibilityAttributeであるものと見なされます、DesignerSerializationVisibilityAttributeの値を持つVisibleします。Members that do not have a DesignerSerializationVisibilityAttribute will be treated as though they have a DesignerSerializationVisibilityAttribute with a value of Visible. プロパティの値がマークVisibleはでシリアル化、可能であれば、型のシリアライザー。The values of a property marked as Visible will be serialized, if possible, by a serializer for the type. 特定の種類またはプロパティのカスタムのシリアル化を指定するには、使用、DesignerSerializerAttributeします。To specify custom serialization for a particular type or property, use the DesignerSerializerAttribute.

詳細については、「属性」を参照してください。For more information, see Attributes.

コンストラクター

DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility) DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility) DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility) DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility)

指定した DesignerSerializationVisibility 値を使用して、DesignerSerializationVisibilityAttribute クラスの新しいインスタンスを初期化します。Initializes a new instance of the DesignerSerializationVisibilityAttribute class using the specified DesignerSerializationVisibility value.

フィールド

Content Content Content Content

シリアライザーがプロパティ自体ではなくプロパティの内容をシリアル化することを指定します。Specifies that a serializer should serialize the contents of the property, rather than the property itself. このフィールドは読み取り専用です。This field is read-only.

Default Default Default Default

既定値 (Visible) を指定します。つまり、ビジュアルなデザイナーは既定の規則を使用してプロパティの値を生成します。Specifies the default value, which is Visible, that is, a visual designer uses default rules to generate the value of a property. static フィールドは読み取り専用です。This static field is read-only.

Hidden Hidden Hidden Hidden

シリアライザーがプロパティの値をシリアル化しないことを指定します。Specifies that a serializer should not serialize the value of the property. static フィールドは読み取り専用です。This static field is read-only.

Visible Visible Visible Visible

シリアライザーによるプロパティの値のシリアル化を許可するように指定します。Specifies that a serializer should be allowed to serialize the value of the property. static フィールドは読み取り専用です。This static field is read-only.

プロパティ

TypeId TypeId TypeId TypeId

派生クラスで実装されると、この Attribute の一意の識別子を取得します。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)
Visibility Visibility Visibility Visibility

プロパティの値を永続化するかどうかと永続化の方法を決定するときにシリアライザーが使用する基本的なシリアル化モードを示す値を取得します。Gets a value indicating the basic serialization mode a serializer should use when determining whether and how to persist the value of a property.

メソッド

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

このインスタンスと指定したオブジェクトが等しいかどうかを示します。Indicates whether this instance and a specified object are equal.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

このオブジェクトのハッシュ コードを返します。Returns the hash code for this object.

GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

属性の現在の値が既定値かどうかを示す値を取得します。Gets a value indicating whether the current value of the attribute is the default value for the attribute.

Match(Object) Match(Object) Match(Object) Match(Object)

派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

明示的なインターフェイスの実装

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

オブジェクトの型情報を取得します。この情報はインターフェイスの型情報の取得に使用できます。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

適用対象

こちらもご覧ください