I am dynamically adding inkedits(rich textboxes for all intents and purposes) to a form and i want to capture the F2 key when the focus is on one of them and that key is hit...
I wanted to do addhandler inkedits.keypress but that event only works for ascii keys.
If i try inkedits.keyup the compiler is expecting a delegate object..
the examples i can find through searching the web dont really help me with the syntax..
i know i need to declare a delegate but i dont see how i can get it so i can create the code to handle the F2 event and create the instance of that delegate...
Thanks for any help you can give.
Confusedly,
Dan

Delegates and KeyUp
Vijay Subramani
I am not using the designer to add my inkedits i am doing it programmatically. when the user selects a template to load i create it there.
so in my parse file subroutine i need to do something like
addhandler inkedititem.keyup, addressof <something>
but i cannot figure out the syntax. the compiler wants a delegate in place of the something...
MAMMOTH_MK
How do i add / what is the syntax for a keyup delegate / function that will capture the F2 key
Thanks,
//globals
Dim GlobalKeyHandler As KeyUpDelegate//form_1load
'point the delegate to the desired function
GlobalKeyHandler =
AddressOf KeyUpHandler//define the delegate and function
Public Delegate Sub KeyUpDelegate(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Public Sub KeyUpHandler(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) End Sub//inside add inkedit loop
**** it doesnt like this because GlobalKeyHandler isnt a method...but it insists on a delegate object...huh
AddHandler
InkEditItem.KeyUp, addressof GlobalKeyHandler !errordigital rebel
quacka
Brian Brashear
The simplest form of Delegate is as follows:
Private Delegate Sub DelMyProcedure(Byval Parameter1 as String, Byval Parameter2 as String)
Private Sub MyProcedure(Byval Parm1 as String, Byval Parm2 as String)
If WhateverControl.InvokeRequired Then
Dim poCB as New DelMyProcedure(AddressOf MyProcedure)
Dim poParm(1) as Object
poParm(0) = Parm1
poParm(1) = Parm2
WhateverControl.Invoke(poCB, PoParm)
Else
WhateverControl.WhateverProperty = Parm1
WhateverControl.AnotherPropert = Parm2
End If
End Sub
Typed from memory so I appologize for any typo's.
Johan Stenberg
I found a lame way to handle it. make an invisible menu strip item with function key shortcut and handle the click. its lame but it works. I would not have thought that getting the function keys would be a such a chore in .net....bleah. i would apperciate a "real" answer is anyone has one.
Thanks,
Dan
boest02
I have a similar issue for the Euchre game that I wrote. I decided to let the form handle the F2 key (since it always exists, and I therefore avoid adding handlers all over the place) , and then I'd worry about what was selected in the handler.
Private Sub EuchreTable_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp If e.KeyCode = Keys.F2 Then// .... figure stuff out here ...
End If End SubBasically, I just went to the drop-downs, selected the "EuchreTable" events on the left, the "KeyUp" on the right, filled in the check for Keys.F2 and that was pretty much it.
I hope this helps -- if not, I'll follow up.
--Matt--*
AleksL
ThisIsBrianS
I swear i tried that same approach 10 times and the compiler kept squaking about wanting a delegate...and wouldnt accept that sub routine..dunno what the problem was but it works now.
Thanks!
Lee Stallworth
You basically need to declare a function that has the same signature as the delegate. In this case Matt already provided you with the signature that you need to use:
Private Sub KeyUp_Handler(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyCode = Keys.F2 Then
// .. figure stuff out here ...
End If
End Sub
Then you just need to call AddHandler with the event name and the address of the method handler like this:
AddHandler inkedititem.keyup, AddressOf Keyup_Handler
Don't forget to call RemoveHandler when you don't need the object anymore.
Hope that helps,