Make Your First ActiveX Control

Lesson 2
Tutorials - Page 1 - Page 2 - Page 3 - Page 4 - Page 5 - Page 6 - Page 7

Adding more properties to the control
Now we want that the control will have all the Command Button properties.
lets add the BackColor property. Enter the following code to your form:

Public Property Get BackColor() As OLE_COLOR
    BackColor = Command1.BackColor
End Property

Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
    Command1.BackColor() = New_BackColor
    PropertyChanged "BackColor"
End Property

Enter the following line to the UserControl_ReadProperties function:
Command1.BackColor = PropBag.ReadProperty("BackColor", &H8000000F)

Enter the following line to the UserControl_WriteProperties function:
Call PropBag.WriteProperty("BackColor", Command1.BackColor, &H8000000F)

The OLE_COLOR is the type of the BackColor property variable,
the same as the Boolean is the type of the Enabled property variable,
and the Integer is the type of the Height property variable.

What we did now is almost the same as we did with the Text property.
The difference is that in the text property we used
a variable (TextVariable) to store the property information.
Here we not using a variable, we read and write the information
directly to the Command1.BackColor property.

The Command1.BackColor property is here our variable that store
the information. Why is that?
Because when the user set the Control BackColor property,
we actually want to set the Command1 BackColor property.
Suppose the user set the Control BackColor to Black.
In that case, We want to set the Command1 BackColor to Black.
So actually, the Control BackColor property is the
Command1 BackColor property.
So instead of reading and writing to variable,
we read and write directly to the Command1 BackColor property.

It's exactly the same thing with all of the other properties.

Back  Forward