本文整理匯總了C#中System.ComponentModel.DesignerSerializationVisibilityAttribute類的典型用法代碼示例。如果您正苦於以下問題:C# DesignerSerializationVisibilityAttribute類的具體用法?C# DesignerSerializationVisibilityAttribute怎麽用?C# DesignerSerializationVisibilityAttribute使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DesignerSerializationVisibilityAttribute類屬於System.ComponentModel命名空間,在下文中一共展示了DesignerSerializationVisibilityAttribute類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ContentSerializationExampleControl
//引入命名空間
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;
}
}
}
}