For more on this subject Google Search on VB Initproperties
You may wonder why we need the InitProperties event since the UserControl property already has an Initialize event in common with Class modules and other objects, such as forms.
The reason that we need InitProperties to initialize default values is that the Initialize event happens too often, that is, every time an instance or your control "wakes up." You only want the default property values to be assigned when the developers first sites a new copy of your control on a container. After that, you want the developer to be able to define persistent property values.
WARNING – Don't Use the Initialize Event to Set an ActiveX Control's Default Property Values : If you put code to initialize properties to their default values in your custom ActiveX control's Initialize event instead of in the InitProperties event, then you will have some very frustrated developers on your hands. Your default values will override the values the developer has assigned at design time every time the developer runs an application using your control.
—
The Property Bag is a persistent UserControl object containing the values of your control's custom, extender, and delegated properties. In fact, the Property Bag is so persistent that it doesn't get destroyed with the instances of the UserControl. This means you can store property values in the Property Bag just before an instance of the UserControl is destroyed and then retrieve the stored values when a new instance of the UserControl "wakes up" in another part of the development life cycle.
The Property Bag has two methods to store and retrieve values respectively:
-
The WriteProperty method
-
The ReadProperty method
You must know how to manipulate the Property Bag in the following situations that we discuss in the sections immediately following this one:
-
You store property values into the PropertyBag by calling its WriteProperty method in the WriteProperties event procedure.
-
You retrieve property values from the PropertyBag by calling its ReadProperty method in the ReadProperties event procedure.
-
You ensure that the WriteProperties event will fire by calling the PropertyChanged method. You'll usually do this in the Property Let procedures of your custom properties or at other appropriate places in your code where the storage value of a property changes.
—-
The operating environment fires a UserControl's ReadProperties and WriteProperties events whenever it thinks that the instantiated object's properties need to be re-initialized (ReadProperties event fires) or stored for safekeeping (WriteProperties event fires).
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.
…………more