Click here to Skip to main content
15,889,878 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Its a long time I came back to windows development from web and feeling something is missing...

Well, the question is I have Label property in a custom control. Now when I set its Text property(Label's) at design time, it appears good but when run, Text comes back to default. Its because the design.cs file do not have code like this

this.CustomControl1.Title.Text = "something to appear";



The following code snippet from source


Label _title;
public Label Title
{
    get { return _title; }
  // set { _title = value; }
}


and on constructor (.ctor)

 _title = new Label();
            _title.AutoSize = true;
            _title.Text = "Title";
....
Posted

Finally, I grabbed its neck

all I needed was to put [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] above the property

final look

Label _title;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Label Title
{
    get { return _title; }
    // set { _title = value; }
}
 
Share this answer
 
If there is no setter defined, I dont think you can set its properties. It will through compilation error for you.

If the control is created by you, make sure that the setter sets the value properly. This might be the case for you.




Xmen W.K. : Even there is setter it doesn't work. Plus setter in that case will be only for Label. Label properties can be change even there is only getter.
 
Share this answer
 
It seems you have stumbled upon IDE bug. Designer does not automatcly add code if you use sub-propeties of Title. You would need to do it manualy or do it OnLoad event.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900