Using the Interop Forms Toolkit in VFP9 – A Walkthrough II
Part 2 - Properties and More Events
Today I will show how we can add additional controls as well as expose properties of those controls in our Activex.
If you haven't already please read Part 1 of the post.
Open the project in vbExpress you created earlier or if you’re lazy download the complete project code from the link below and follow along.
Double click the file MyToolstrip.vb to open it in the designer. From the toolbox on the left drop a checkbox onto the usercontrol surface. Change these properties:
(Name) = chkOnOff
Autosize = True
Text = OnOff
And move it to the centre of the control as shown.

Pic1
Now we want to expose certain properties of this check box so that we can access and set them in VFP. The properties I have chosen are:
Property
Top
Left
Text (vfp Caption)
Event
Checked or not checked (VFP value)
But you can expose any properties in a similar way.
Just below the area where you declared the Public events, add these declarations as shown:
' Interop Properties code
Public Property Checked() As Boolean
Get
Return Me.chkOnOff.Checked
End Get
Set(ByVal value As Boolean)
Me.chkOnOff.Checked = value
End Set
End Property
Public Property chkTop() As Integer
Get
Return Me.chkOnOff.Top
End Get
Set(ByVal value As Integer)
Me.chkOnOff.Top = value
End Set
End Property
Public Property ChkLeft() As Integer
Get
Return Me.chkOnOff.Left
End Get
Set(ByVal value As Integer)
Me.chkOnOff.Left = value
End Set
End Property
Public Property ChkCaption() As String
Get
Return Me.chkOnOff.Text
End Get
Set(ByVal value As String)
Me.chkOnOff.Text = value
End Set
End Property
I have given them unique names so that I can find them when I add the control from VFP. If I had just used TOP then if there were more controls I would not be able to differentiate them from the TOP of other objects.
Finally we want to expose the “Changed” event so that we can trap this when the value is changed in VFP. So add this Event declaration as the last event
Public Event ChkOnOffChanged()
and after the Property declarations add this code to raise the event.:
Private Sub chkOnOff_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkOnOff.CheckedChanged
RaiseEvent ChkOnOffChanged()
End Sub
That is all. Now save and compile your project.
Note: If you have previously opened the Activex in VFP you will get a write error on build. Just close VFP and build again.
In VFP, open your test form (toolstriptester.scx from the download) and you will find the checkbox has been added.
If you open the properties window of the Olecontrol you will see that we now have an additional event and some extra properties:

Pic2
As we do in VFP we now need some control over the object. So open the INIT of the form and add this code:
Form.Init Code
WITH This as form
WITH .olecontrol1
.chkCaption = "Tick to allow data entry"
.chkTop = 35
.chkLeft = 50
ENDWITH
ENDWITH
Open the code window for the ChkOnOffChanged Event and add this code:
Olecontrol1.Chkchanged code
WAIT WINDOW NOWAIT "The value in the checkbox has been changed to :"+IIF(This.checked,".T.",".F.")
Now run your form and see that the Caption has been changed and that you have been able to re position the checkbox. You can also click the checkbox to change its value and trap this change.

Pic3
In the next post we’ll tackle exposing default and custom methods.
Have fun.