Now, place the code behind the menu's click event procedure. Since the
menu was set up as an array, only one event procedure is necessary. We can determine which
menu item was selected by the Index argument passed to the procedure. The
following routine sends the appropriate keystrokes to the form which Windows intercepts
and handles accordingly. The code looks like the following: Sub mnuEdit_Click (Index As Integer)
*******************************************************
'<DESC> Routine for handling common edit menu
' functions</DESC>
'<ARGS> Index: Edit Menu Index<ARGS>
'<USAGE> mnuEdit_Click(1)</USAGE>
'*******************************************************
Select Case Index
Case 0
SendKeys "%{BACKSPACE}" ' Undo
Case 1
SendKeys "+{DELETE}" ' Cut
Case 2
SendKeys "^{INSERT}" ' Copy
Case 3
SendKeys "+{INSERT}" ' Paste
End Select
End Sub
Now, place a couple of text boxes on the form. To test this procedure, run the program
and enter some text into one of the text boxes. Select the text and choose Cut from the
Edit Menu. Then select the second text box and choose Paste from the Edit Menu. Then
select the first text box and choose Undo from the Edit Menu. Continue playing around with
the menu to see how it all works. |