DesignerSerializationVisibilityAttribute クラス
デザイン時にコンポーネントのプロパティをシリアル化するときに使用する永続化の種類を指定します。
この型のすべてのメンバの一覧については、DesignerSerializationVisibilityAttribute メンバ を参照してください。
System.Object
System.Attribute
System.ComponentModel.DesignerSerializationVisibilityAttribute
<AttributeUsage(AttributeTargets.Method Or _
AttributeTargets.Property)>
NotInheritable Public Class _ DesignerSerializationVisibilityAttribute Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Method |
AttributeTargets.Property)]
public sealed class DesignerSerializationVisibilityAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Method |
AttributeTargets::Property)]
public __gc __sealed class DesignerSerializationVisibilityAttribute : public Attribute
[JScript]
public
AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)
class DesignerSerializationVisibilityAttribute extends Attribute
スレッドセーフ
この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
解説
シリアライザでデザイン モード ドキュメントの永続化状態を設定する場合に、デザイン時に設定されたプロパティの値を永続化するために、コンポーネントの初期化メソッドにコードを追加することがよくあります。他の動作を指示する属性が設定されていなければ、ほとんどの基本的な型に対して、既定でこれが行われます。
DesignerSerializationVisibilityAttribute を使用すると、プロパティの値を Visible として初期化コードで永続化するのか、 Hidden として初期化コードで永続化しないのか、または Content として、そのプロパティに代入するオブジェクトのパブリックな、隠ぺいされていない各プロパティに対して初期化コードを生成する必要があるのかを示すことができます。
DesignerSerializationVisibilityAttribute のないメンバは、値が Visible の DesignerSerializationVisibilityAttribute を持つものとして扱われます。 Visible としてマークされたプロパティの値は、可能であれば、その型のシリアライザでシリアル化されます。特定の型やプロパティに対してカスタムのシリアル化を指定するには、 DesignerSerializerAttribute を使用します。
詳細については、「 属性の概要 」および「 属性を使用したメタデータの拡張 」を参照してください。
使用例
[Visual Basic, C#, C++] Content に設定した DesignerSerializationVisibilityAttribute を使用して、デザイン時に設定できるユーザー コントロールのパブリック プロパティの値を永続化する例を次に示します。この例を使用するには、最初に次のコードをコンパイルして、ユーザー コントロール ライブラリを作成します。次に、新しいプロジェクトへの参照をコンパイルした .DLL ファイルに追加し、コントロールを .DLL ファイルからデザイン モードのツールボックスに追加します。これを行うには、ツールボックスを右クリックし、[ツールボックスのカスタマイズ] をクリックして、ユーザー コントロールが含まれる .DLL ファイルからコントロールを選択します。次に、コントロールをツールボックスからフォームにドラッグし、コントロールを選択した状態で、プロパティ一覧に表示される 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
[C#]
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;
}
}
}
}
[C++]
#using <mscorlib.dll>
#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;
[TypeConverterAttribute(__typeof(System::ComponentModel::ExpandableObjectConverter))]
// This attribute indicates that the public properties of this object should be listed in the property grid.
public __gc class DimensionData
{
private:
Control* owner;
// This class reads and writes the Location and Size properties from the Control which it is initialized to.
public private:
DimensionData(Control* owner)
{
this->owner = owner;
}
public:
__property Point get_Location()
{
return owner->Location;
}
__property void set_Location( Point value )
{
owner->Location = value;
}
__property Size get_FormSize()
{
return owner->Size;
}
__property void set_FormSize( 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 __gc class ContentSerializationExampleControl : public System::Windows::Forms::UserControl
{
private:
System::ComponentModel::Container* components;
public:
[DesignerSerializationVisibility(DesignerSerializationVisibility::Content)]
__property DimensionData* get_Dimensions()
{
return new DimensionData(this);
}
ContentSerializationExampleControl()
{
InitializeComponent();
}
protected:
void Dispose( bool disposing )
{
if( disposing )
{
if( components != 0 )
components->Dispose();
}
UserControl::Dispose( disposing );
}
private:
void InitializeComponent()
{
components = new System::ComponentModel::Container();
}
};
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.ComponentModel
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
アセンブリ: System (System.dll 内)
参照
DesignerSerializationVisibilityAttribute メンバ | System.ComponentModel 名前空間 | Attribute | PropertyDescriptor | AttributeCollection | PropertyDescriptorCollection