心如止水

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

         1.  DesignerSerializationVisibility

指在design time的时候,在property grid中设置的某个属性的值是否应该插入到InitializeComponent的代码中去。

·         Visible 默认值,会插入中去。

·         Hidden 不会插入中去。

·         Content  将该属性中所有的为public的子属性插入中去。

例如下面的例子:
public partial class ContentSerializationExampleControl : UserControl
    {
        
public ContentSerializationExampleControl()
        {
            InitializeComponent();
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        
public DimensionData Dimensions
        {
            
get
            {
                
return new DimensionData(this);
            }
        }

        [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;
                }
            }
        }
    }
则DimensionData的Location和FormSize属性都会出现在InitializeComponent中。

2. Category:指定属性出现在property grid中的哪个组中。
3. Browsable:指定属性是否显示在property grid中

posted on 2009-03-19 14:38  cutebear  阅读(926)  评论(0编辑  收藏  举报