I have a control, with a certain property that requires a somewhat heavy init routine be called every time the property is changed.
Of course, the public property isn’t required to be set initially, but the init routine must be called with a default value.
How can I structure this, so that the init routine is only called once, regardless of whether the designer set the property or not?
Currently, it is called once in the constructor, and then again when the property setter is called through designer code (if specified). What’s a good way of dealing with this?
If you place the
DefaultValueAttributein front of your property, specifying the actual default value of your property, the windows forms designer will not generate code that initializes the propertyProperties are only initialized in
InitializeComponent();if the value specified in the properties window differs from the specified default value.If you do not need to set this property in the properties window at all, then you can hide it from the properties window with the
BrowsableAttribute. You can disable serialization (code generation forInitializeComponent) completely with theDesignerSerializationVisibilityAttribute.