February 28, 2021
Hot Topics:

ActiveX Controls: The Definitive Guide

  • By Sam Huggill
  • Send Email »
  • More Articles »

A control's greatest feature is the ability to have properties. You have been using properties all the time. This line, Text1.Text="" is using the Text property of the text box. When using properties in VB you need to define procedures to set and return the value of the property. These are called Let and Get property procedures.

Here are two typical property procedures:

Property Get Name() As String
End Property

Property Let Name(ByVal New_Name As String)
  PropertyChanged "Name"
End Property

Visual Basic provides you with an easy tool to quickly generate these properties. This is called the ActiveX Control Wizard. You can show this toolbar by selecting View, Toolbars, Add-In Toolbar. Click on this button and choose the properties that you want. In this example, we want BackColor, Enabled, Font and ForeColor. We will deal with events later. On the next screen make sure that you map these properties to Usercontrol.

Now open up the code window for the control, and there you are, lots of nice procedures generated by VB.

You will notice the ReadProperties and WriteProperties procedures. These procedures actually control the storage of the properties. E.g. If you set the font of a control at design time, run and then end the program you still want the control to have the same font. These properties handle this.

They store the information in what's called the controls PropertyBag. This is just an area of memory dedicated to storing information about the controls properties. You need to define calls to carry out these actions.

As you can see from the property procedures that the Let procedures use the PropertyChanged keyword. This keyword alerts the control that a property has been changed. Aside to that keyword, the property Let procedure can be used to apply separate settings such as applying the new Font to the controls on your ActiveX control.

Page 2 of 3

This article was originally published on November 20, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date