Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expose whole sub control of usercontrol at winforms designer

For example I want to create a usercontrol(windows form) that contains a lable and a textbox . And I want to expose the two sub control as property , so that I can set the sub control's property in client form designer.

so the code maybe like this :

 public partial class LabelTextbox : UserControl
    {
        public LabelTextbox()
        {
            InitializeComponent();
        }

        [
           Category("Appearance"),
           Browsable(true),
           Description("innerLabel")
        ]
        public DevComponents.DotNetBar.LabelX LabelPart
        {
            get
            {
                return this.labelx;
            }

            set
            {
                this.labelx = value;
            }
        }


        [
           Category("Appearance"),
           Browsable(true),
           Description("InnerTextbox")
        ]
        public TextBox TextBoxPart
        {
            get
            {
                return this.textboxx;
            }

            set
            {
                this.textboxx = value;
            }
        }
    }

and then I can see it in designer , it looks like :

enter image description here

but when I set the usercontrol's inner label property in designer , it can't make relation code in the designer.cs . that's to say the client settings not be saved .

so how can I resolve this problem.

By the way I come from CN my English is poor . Anyone can answer me.

like image 776
user1754971 Avatar asked Oct 18 '12 03:10

user1754971


1 Answers

Decorate the properties of your child Controls with the DesignerSerializationVisibility Attribute:

[
   Category("Appearance"),
   Browsable(true),
   Description("innerLabel"),
   DesignerSerializationVisibility(DesignerSerializationVisibility.Content)  //<-- here
]
public DevComponents.DotNetBar.LabelX LabelPart {
    get {
        return this.labelx;
    }
    set {
        this.labelx = value;
    }
}
like image 90
Jay Riggs Avatar answered Nov 14 '22 20:11

Jay Riggs