2
votes

I am defining a user control deriving from TextBox class in Windows Forms. The user control defines a property IsMandatory. If this property is set to true I am calling a function which does something to the look of user control.

When I used this control on my Form in design time, I am able to set this property. But the designer file doesn't seem to change. It doesn't have the code that sets this value.

IsMandatory is a boolean property. Either I set it to true or false in designer, no corresponding code is there in the designer file. Why is that?

1

1 Answers

2
votes

Try this:

public partial class MyTextBox : TextBox
{
    public MyTextBox()
    {
        InitializeComponent();
    }

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public bool IsMandatory { get; set; }

}

That DesignerSerializationVisiblity setting will store off the bool value in the .designer file.

That said, it isn't necessary to specify "Visible" since that is the default, I believe. Are you setting it to "Hidden" perhaps?