DesignerSerializationVisibilityAttribute Sınıf
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Tasarım zamanında bir bileşendeki bir özelliği seri hale getirdiğinizde kullanılacak kalıcılık türünü belirtir.
public ref class DesignerSerializationVisibilityAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Method | System.AttributeTargets.Property)]
public sealed class DesignerSerializationVisibilityAttribute : Attribute
public sealed class DesignerSerializationVisibilityAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property)]
public sealed class DesignerSerializationVisibilityAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Method | System.AttributeTargets.Property)>]
type DesignerSerializationVisibilityAttribute = class
inherit Attribute
type DesignerSerializationVisibilityAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property)>]
type DesignerSerializationVisibilityAttribute = class
inherit Attribute
Public NotInheritable Class DesignerSerializationVisibilityAttribute
Inherits Attribute
- Devralma
- Öznitelikler
Örnekler
Aşağıdaki kod örneğinde olarak ayarlanmış bir DesignerSerializationVisibilityAttribute kümenin Contentkullanımı gösterilmektedir. Bir kullanıcı denetiminin ortak özelliğinin değerlerini kalıcı hale alır ve bu değer tasarım zamanında yapılandırılabilir. Örneği kullanmak için önce aşağıdaki kodu bir kullanıcı denetim kitaplığında derleyin. Ardından, yeni bir Windows Uygulaması projesinde derlenmiş .dll dosyasına başvuru ekleyin. Visual Studio kullanıyorsanız ContentSerializationExampleControl otomatik olarak Toolbox eklenir.
denetimi Toolbox bir forma sürükleyin ve Özellikler penceresi listelenen DimensionData nesnesinin özelliklerini ayarlayın. Formun kodunu görüntülediğinizde, kod üst formun InitializeComponent yöntemine eklenir. Bu kod, denetimin özelliklerinin değerlerini tasarım modunda ayarladığınız değerlerle ayarlar.
#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.ComponentModel;
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 : UserControl
{
Container components;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public DimensionData Dimensions => new(this);
public ContentSerializationExampleControl() => InitializeComponent();
protected override void Dispose(bool disposing)
{
if (disposing)
{
components?.Dispose();
}
base.Dispose(disposing);
}
void InitializeComponent() => components = new Container();
}
[TypeConverter(typeof(ExpandableObjectConverter))]
// This attribute indicates that the public properties of this object should be listed in the property grid.
public class DimensionData
{
readonly 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 => owner.Location;
set => owner.Location = value;
}
public Size FormSize
{
get => owner.Size;
set => owner.Size = value;
}
}
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
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
Private Sub InitializeComponent()
End Sub
End Class
' 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
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
End Namespace 'DesignerSerializationVisibilityTest
Açıklamalar
Seri hale getirici, tasarım modu belgesinin kalıcı durumunu kalıcı hale getirdiğinde, genellikle tasarım zamanında ayarlanmış özelliklerin değerlerini kalıcı hale getirmek için bileşenlerin başlatma yöntemine kod ekler. Başka bir davranışı yönlendirmek üzere ayarlanmış bir öznitelik yoksa, bu çoğu temel tür için varsayılan olarak gerçekleşir.
ile, bir özelliğin DesignerSerializationVisibilityAttributeVisibledeğerinin , ve başlatma kodunda kalıcı olması ve başlatma kodunda Hiddenkalıcı olmaması gerektiğini veya özelliğine atanan nesnenin gizli özelliği için değil her genel için başlatma kodu oluşturulması gereken öğesinden oluşup Contentoluşmadığını belirtebilirsiniz.
sahip olmayan DesignerSerializationVisibilityAttribute üyeler, değerine Visiblesahipmiş DesignerSerializationVisibilityAttribute gibi değerlendirilir. olarak Visible işaretlenen bir özelliğin değerleri, türü için bir seri hale getirici tarafından mümkünse serileştirilir. Belirli bir tür veya özellik için özel serileştirme belirtmek için kullanın DesignerSerializerAttribute.
Daha fazla bilgi için bkz . Öznitelikler.
Oluşturucular
| Name | Description |
|---|---|
| DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility) |
Belirtilen DesignerSerializationVisibilityAttribute değeri kullanarak sınıfın DesignerSerializationVisibility yeni bir örneğini başlatır. |
Alanlar
| Name | Description |
|---|---|
| Content |
Seri hale getiricinin özelliğin kendisi yerine özelliğin içeriğini seri hale getirmesi gerektiğini belirtir. Bu alan salt okunurdur. |
| Default |
Varsayılan değeri belirtir( Visibleyani, görsel tasarımcı bir özelliğin değerini oluşturmak için varsayılan kuralları kullanır). Bu |
| Hidden |
Bir seri hale getiricinin özelliğin değerini seri hale getirmemesi gerektiğini belirtir. Bu |
| Visible |
Bir serileştiricinin özelliğin değerini seri hale getirmesine izin verilmesi gerektiğini belirtir. Bu |
Özellikler
| Name | Description |
|---|---|
| TypeId |
Türetilmiş bir sınıfta uygulandığında, bu Attributeiçin benzersiz bir tanımlayıcı alır. (Devralındığı yer: Attribute) |
| Visibility |
Bir seri hale getiricinin bir özelliğin değerinin kalıcı olup olmadığını ve nasıl kalıcı hale getirildiğini belirlerken kullanması gereken temel serileştirme modunu belirten bir değer alır. |
Yöntemler
| Name | Description |
|---|---|
| Equals(Object) |
Bu örneğin ve belirtilen nesnenin eşit olup olmadığını gösterir. |
| GetHashCode() |
Bu nesnenin karma kodunu döndürür. |
| GetType() |
Geçerli örneğin Type alır. (Devralındığı yer: Object) |
| IsDefaultAttribute() |
Özniteliğin geçerli değerinin öznitelik için varsayılan değer olup olmadığını belirten bir değer alır. |
| Match(Object) |
Türetilmiş bir sınıfta geçersiz kılındığında, bu örneğin belirtilen bir nesneye eşit olup olmadığını gösteren bir değer döndürür. (Devralındığı yer: Attribute) |
| MemberwiseClone() |
Geçerli Objectbasit bir kopyasını oluşturur. (Devralındığı yer: Object) |
| ToString() |
Geçerli nesneyi temsil eden bir dize döndürür. (Devralındığı yer: Object) |
Belirtik Arabirim Kullanımları
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Bir ad kümesini karşılık gelen bir dağıtma tanımlayıcısı kümesine eşler. (Devralındığı yer: Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Bir arabirimin tür bilgilerini almak için kullanılabilecek bir nesnenin tür bilgilerini alır. (Devralındığı yer: Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Bir nesnenin sağladığı tür bilgisi arabirimlerinin sayısını alır (0 ya da 1). (Devralındığı yer: Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Bir nesne tarafından kullanıma sunulan özelliklere ve yöntemlere erişim sağlar. (Devralındığı yer: Attribute) |