Welcome to Foxite.COM Community Weblog Sign in | Join | Help

Bernard Bout

May the Fox be with you...

<June 2007>
SuMoTuWeThFrSa
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

Post Categories

News

site statistics

Locations of visitors to this page

Navigation

Some VFP links

Others...

Archives

Who links to this site?

Hey There!!!

Syndication




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.

 

 

Published Thursday, June 21, 2007 2:36 PM by bbout
Filed Under:
Attachment(s): bbToolstrip.zip

Comments

# re: Using the Interop Forms Toolkit in VFP9 – A Walkthrough II @ Thursday, July 05, 2007 9:30 PM

Cool tutorial Bernard! I've managed to keep up with your instructions and things are working very nicely. Can't wait for you to continue.

Any chance you'll be using the .NET Menustrip control? I'd really like to see how we can use it as a substitute for the VFP menu. The latter is so dated.

Thanks for your interest Mike. I will make "how we can use it as a substitute for the VFP menu" my next post. With the current state of things, (without a wizard) you will have to construct the menu by hand in .Net and export the settings to be able to use in VFP.

MikeS

New Comments to this post are disabled
Powered by Community Server, by Telligent Systems