I've red that those methods of ISupportInitialize
interface are used by Designer to support optimization, to ensure atomicity of initialization of controls, and to prevent any action on controls during initialization. My questions are:
It does not have anything to do with optimization. ISupportInitialize
is an interface that you need when your control is sensitive to the order in which properties are assigned. There isn't any way to affect the order in which the designer assigns them, it does it alphabetically.
You typically set a bool variable to true in your BeginInit()
method, you test this in the property setters and don't do anything when it is set. Your EndInit()
method then makes the property values effective.
You can see a good example of this in the ErrorProvider component. Note how it uses the methods to defer data binding. The PictureBox control is another good example, it uses it to defer image downloading. TrackBar is yet another example, it uses it to ensure that the Value
property is between Minimum and Maximum. Etcetera, the .NET Framework source is often a very good place to see how .NET types are used in practice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With