Using the Interop Forms Toolkit in VFP9 III
Part 3 – Adding and Enabling a Menu Strip
In this post I will expand on my other posts (1 & 2 ) and show how we can add a menu strip and use it from VFP. You will need to download the source code supplied in the previous post to follow along.
Mike S has requested this segment so here ya go Mike…
Open up the project in VBExpress.Net and you are good to go.
Adding a “menu strip” is very easy. Double click the file MyToolstrip.vb to open it in the design window. From the toolbox locate the MenuStrip control and select it. Click on your form to add it to the form.
For this example we will use the defaults provided same as the tool buttons. So Right Click on the MenuStrip and select “Insert Standard Items”. A standard set of menu items will be added as shown.

In the Code Window (double click anywhere on the control or from the menu View|Code), just below the last event you published, add this event:
'Please enter any new code here, below the Interop code
' these events will be published
Public Event NewDocument()
Public Event Open()
Public Event Save()
Public Event Print()
Public Event Cut()
Public Event Copy()
Public Event Paste()
Public Event Help()
Public Event ChkOnOffChanged()
' Handle all menu events here <<<--- This is what you need to add
Public Event MenuItemSelected(ByVal Menuname As String)
The final thing is to create events for each MenuClick.
To do this just double click each menu item in Design View, and this will open the code view with the click method setup. All that is needed is to paste the following line (bold) into each method:
Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
RaiseEvent MenuItemSelected(sender.name)
End Sub
I have done this for only the File menu items. You will need to do this for all menu items.
Once that is done just rebuild the control. We have finished with VB.Net.
In VFP open your testform and see that the form control now contains the Menu items as well.

All that is needed now is to wire in the Menu handler. So in VFP, open the code window for the OleControl.MenuItemSelected. This is the new Event we exposed earlier. The code window opens with the Parameter statement already there. This is because we specified that there was a parameter to be passed by the event when we exposed this event in VB.
Add the following snippet of code.
*** ActiveX Control Event ***
LPARAMETERS menuname
LOCAL cMenu as String
cMenu = UPPER(STRTRAN(menuname,"ToolStripMenuItem",""))
IF cMenu = "EXIT"
ThisForm.Release
ELSE
WAIT WINDOW NOWAIT "You selected menu item :"+cMenu
ENDIF
Basically you have to handle the menu clicks here in one place. This can easily be achieved using a CASE…ENDCASE statement for each menu item. The name of the Menu item is passed so I just strip off the excess to reveal the menu clicked.
Now run your form and begin using the menu. Notice that Exit actually quits the form?

Thanks to Mike S for his suggestion. Actually Mike, this was on my “nextpost” list :)