Wednesday, July 25, 2007


Often after setting Property value for your ActiveX control at design time, you find them missing or replaced by default values during runtime.To make Property values to persist, you need to make use of PropertyBag object.

Suppose you are creating a property MyText for your ActiveX Control, then to make it persist you need to write the new settings using PropertyBag object, which stores them on disk.

Public Property Let MyText(ByVal Value As String)
myTextBox.Text = Value
Call PropertyChanged("MyText")
End Property

Public Property Get MyText() As String
MyText = myTextBox.Text
End Property

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
myTextBox.Text = PropBag.ReadProperty("MyText")
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("MyText", myTextBox.Text)
End Sub