The easiest way to specify a default value of a property is to create a constant called something like this:
Const m_def_Text = "Default Value" '// default value of Text
property
Then, add the following code to your control (presuming you already have a m_Text variable, a m_def_Text constant and a Text property):
Private Sub UserControl_InitProperties()
m_Text = m_def_Text '// set Text property to default value
End Sub
Then, you will also need to specify m_def_Text in the WriteProperties and ReadProperties procedures (see below).
If you want to have a property that defaults to the name of the control (such as the caption property of the label control), then you need to do things slightly differently. Firstly, you cannot set a constant for the default value, as you will not know the name of the control (ie Control1, Control2 etc) until run-time. Therefore, you declare a variable called m_def_propertyname instead, and set its value in the UserControl_Initialize procedure:
Private m_def_Text As String
Private Sub UserControl_Initialize()
m_def_Text = UserControl.Name '// set its default value to
the name of the control
End Sub
Comments