I am creating a custom user control and I am wondering how do you set an initial value for a property during design time? I have a property called Alignment that has 4 enum values TopRight, TopLeft, BottomRight and BottomLeft. So, when a user drops the user control onto a Form, I want the initial value of the property to be always BottomRight. How can I do this?
Share
You should set the initial value in the constructor of your user control, or when you declare the backing variable for the property.
The
DefaultValueattribute does not set the initial value. As noted in the documentation, you need to set the initial value in code; the designer will use theDefaultValueattribute to determine whether to generate code to set the property.