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

Navigation

Some VFP links

Others...

Archives

Who links to this site?

Hey There!!!

Syndication




Using the Interop Forms Toolkit in VFP9 – A Walkthrough

Part 1 - Installation, Control Creation & Events

 

Microsoft have recently released the Interop Forms Toolkit 2.0  at http://msdn2.microsoft.com/en-us/vbasic/aa701259.aspx . This toolkit allows developers to create Activex controls that can be hosted in VB as well as forms that can be called from VB. But this toolkit is not limited to VB alone. It can easily be used to create Forms and controls for use in VFP, as I will show.

 

First things first. Go and download the Installer from the page above. The only file you will need is InteropFormToolsInstaller.msi (5.2mb) and install it on your computer.

 

Now this toolkit is meant to be used with the full version of VS.NET as an ADDIN but that is something we really don’t need. The toolkit comes with some template files that will be used to do the heavy lifting in .Net. If you have the full version this will be installed as an Add-in. I use it in the free version of VBExpress.Net. which you can download from Microsoft.

 

Pic1

 

To enable the templates to appear in the Template selection in VB you will need to copy them to a particular location. So fire up explorer and navigate to the location as shown below. You need the ZIP files. VBExpress allows you to specify where it will look for your user templates.

 

Pic2

 

If you have the default directories, this will be

C:\Documents and Settings\bbout\My Documents\Visual Studio 2005\Templates\ProjectTemplates\Visual Basic\  for the templates which are :

VB6 InteropForm Library.zip

VB6 UserControl.zip

 

And the item templates go in

 

C:\Documents and Settings\bbout\My Documents\Visual Studio 2005\Templates\ItemTemplates\Visual Basic which are

VB6 InteropForm Library Info.zip

VB6 InteropForm.zip

VB6 UserControl Item.zip

 

Once you have done that the templates will appear in VBExpress whenever you opt for a new item.

Ok back in VBExpress select New and the New project dialog will appear. Select the VB6 Interop UserControl and rename your project as shown.

 

Pic3

 

VB Express will do its thing and create the files needed for your new user control. You now need to save the project to create the directories. So go ahead and save the project.

 

Pic4

 

One of the files created will be InteropUserControl.vb which we will rename to MyToolstrip.vb.

 

 

Pic5

 

Double click on it or Rt. Click and select “View Designer”. This will open the file ready for editing. From the toolbox on the left select the ToolStrip control and click on the pre-generated user control to add this control to the mix.

 

 

Pic6

 

The user control has no buttons so Rt. Click on it and select “Insert Standard Items”

 

Pic7

 

and standard buttons will be inserted for you..

 

Pic8

 

Now open the Code window (Rt click, “View Code”) and you will be presented with this area of code where you can add your own snippets. We need a way of exposing the events of the buttons so add the following bit of code which will create the events for each button.

 

 

Pic9

 

Next double click on each of the buttons in the Designer view to add an event handler as shown. Delegate the click to our newly created events. Intellisense will help.

 

Pic10 

 

 Pic11

 

That is all that is needed. You can run the control to see how it looks in VB Express. As a final step build the project and the template code will do all the work required to register the control.

 

Pic12

 

Move over to VFP. Create a new form and add an Olecontrol to it. In the dialog that will appear look for and select your control you just created and it will be added to your form.

 

Pic13 

 

Pic14 

 

Click the control and resize it to fit. Set its Anchor = 11

 

Now if you run the form you will see the control, but clicking any of the buttons does nothing. We need to wire in our code to handle the events we created earlier.

 

Double Click the control to open the VFP Code window and you will find the events we created showing up in the drop down list. Lets select the NewDocument Event first.

 

 

Pic15

 

and add code to handle the event when it occurs. For now just enter the code as shown.

 

 

Pic16

 

Do this for each of the events you created.

 

Pic17

 

Now run the form again and click the buttons. Your code will fire as shown. You have just succeeded in creating your first Interop User Control.

 

Pic18

 

Enjoy creating your .Net controls.

 

In my next post we will add in some other controls and expose properties. Till then have fun.

 

Published Wednesday, June 20, 2007 1:22 PM by bbout
Filed Under:

Comments

# re: Using the Interop Forms Toolkit in VFP – A Walkthrough @ Wednesday, June 20, 2007 5:34 AM

Terrific !
For sure it's time for me to download VB Express and try this stuff. Thanks !

Cesar Chalom

# re: Using the Interop Forms Toolkit in VFP – A Walkthrough @ Wednesday, June 20, 2007 7:12 AM

Very Good!!
Funciona!!

MIK

# re: Using the Interop Forms Toolkit in VFP9 – A Walkthrough @ Wednesday, June 20, 2007 9:42 AM

if i create a control as you describe and then use this control in my application would it mean that the end user of my application will need the .net framework installed ?

Yes certainly. Also you will need to register the Activex using Regasm. Your installation program should handle that.

Michael Bickel

# re: Using the Interop Forms Toolkit in VFP9 – A Walkthrough @ Thursday, June 21, 2007 12:57 AM

This is very cool stuff Bernard. I showed this off when I was in Hong Kong last month and uploaded my samples as well. http://blogs.msdn.com/acoat/archive/2007/05/31/net-and-win32-interop-new-toolkit-available.aspx

Cheers,
Andrew

Yup I came across your post and d/l your sample. I was looking for code to expose events but did not find it there. Finally figured it out from the VB toolkit samples. Hence my above post.

I have requested on the forum for a wizard where you can just tick the PEM's you want to expose and the wizard will generate the code. Otherwise it is very time consuming to expose PEM's.

Andrew Coates

# re: Using the Interop Forms Toolkit in VFP9 – A Walkthrough @ Saturday, July 28, 2007 4:32 AM

Great series Bernard! I've enjoyed it very much (so far!!!)

Tod McKenna

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