You can keep information about properties whose values you want to make persistent
in the Property Bag
object of the UserControl.
The Property Bag
object has two methods you will call: ReadProperty
(to retrieve a property's value from the Property Bag
(to store a property's value in the
In addition, you can maintain properties as you would in any ActiveX Class
module: by writing and reading the Private variables that are used to store
the property values between calls to Property procedures.
On the other hand, if you've chosen to implement properties with
Public variables, you can also manipulate and monitor these properties by reading and
writing the Public variables.
You can use these techniques to initialize and maintain persistent property
values in your UserControl.
Here is a list of the events you need to know about to maintain properties.
For each event listed, we tell when the event occurs and give a brief note about how you would
use the event's procedure to maintain persistent property values. We provide more
detailed information on the Property Bag and on these events in the
The InitProperties event happens only once in the lifetime
of a custom control's instance: when the developer actually creates a new instance
of the control by clicking on the control's toolbox icon and placing the new instance
in a container. Use the InitProperties event to set default
initial values for your custom properties and for properties provided by the
The Initialize event is essentially the same as the
Initialize event of any Class module. It happens as the instance of the
UserControl is about to be created.
The ReadProperties event happens whenever an instance
of the control is created. If this is the first time the control has been created
(i.e. the developer has used the toolbox to place a copy of the control on the form),
then ReadProperties happens after
InitProperties. You can put code in the ReadProperties
event procedure to retrieve saved persistent property values.
The WriteProperties event happens whenever an instance
of the control is destroyed and at least one property has been changed (you can notify
the system that a property has been changed by calling the PropertyChange
method of the UserControl). You can put code in
the WriteProperties event procedure to save property values
that you would like to persist.
The Terminate event is essentially the same as the
Terminate event of any Class module. It happens as the instance of the
UserControl is about to be destroyed.
- Using the InitProperties
Event to Set Default Starting Property Values
- The InitProperties Event
Versus the Initialize Event
- Using the Property Bag
to Store Property Values
- Using ReadProperties
and WriteProperties Events and Corresponding
Methods to Maintain Persistent Properties
- Storing Persistent Property Values with the
WriteProperties Event and the WriteProperty
- Calling the PropertyChanged
Method to Trigger WriteProperties
- Retrieving Persistent Property Values with
the ReadProperties Event and the