The operating environment fires a UserControl
events whenever it thinks
that the instantiated object's properties need to be re-initialized (ReadProperties
event fires) or stored for safekeeping (WriteProperties
This arrangement makes it much easier for you, the control author, to manage
these properties since you don't have to think about all the possible occasions when
property values might need reading or writing. You simply need to put code for reading and
writing property values in two centralized places: the ReadProperties and
WriteProperties event procedures.
Both the ReadProperties and WriteProperties
event procedures receive a single parameter named PropBag. This
PropBag parameter obviously represents the Property Bag object
that holds the UserControl's property values.
The PropertyBag object represented by the
PropBag parameter has one method for reading properties (ReadProperty)
and another for writing properties (WriteProperty).
Usually, the only code you need to write in the ReadProperties
event procedure will be a series of calls to the ReadProperty method
so you can retrieve persistent values for individual properties.
Conversely, the only code you usually need to write in the
WriteProperties event procedure will be a series of calls to the
WriteProperty method so you can store persistent values of individual properties.