自定义控件:属性为控件需要注意的地方

如果属性为string、int等类,属性在设计时修改,运行时会保存。

如果属性为控件时,如Label,属性在设计时修改控件的属性,运行时会还原,这时可以通过添加

DesignerSerializationVisibility来支持在运行时保存设置,如:
[DescriptionAttribute("第二个Label获取/设置"), CategoryAttribute("自定义"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public Label SecondLabel
        {
            get { return label2; }
            set { label2 = value; }
        }


原文地址:https://www.cnblogs.com/snake-hand/p/3188463.html