I have a UserControl with a custom property:
public Size TestSize { get; set; }
I would like this property to show up in the properties window during design time of the UserControl, and not only where the UserControl is used as an instance (e.g. when dragged/dropped on a form).
Example: In the designer of the UserControl one can set properties like "AllowDrop", "AutoScroll", "BackColor" etc. I would like my custom property to show up just the same way in the designer.
I have considered and tried adding attributes to the property like:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
but that does not seem to be the way to go.
Any help is appreciated!
If you really want to show the property in the designer of UserControl1
, then the property should belong to its base class. That's because of how designer works
In most cases you don't need to show those properties in designer, unless you want to derive multiple controls from that base and configure that property in design-time of the derived control, but I assume you know your requirement and now you are able to make a decision base on your requiremets.
This is the way that designer works:
.cs
file (and looks for InitializeComponent method, or designer.cs file, also considers the designer-related attributes).Of course there are a lot of other things happening, like making the extender providers working, or pre-filtering or post-filtering properties in design-time, but in general it works like what I explained above.
More information / Related Posts
Some other related answers: