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.

 

5 Responses to Using the Interop Forms Toolkit in VFP9  A Walkthrough

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>