I was not clear. I wanted to have the handler in the class with the callee,
not with the library, so I needed to pass that address to the library sub.
I try to make my post succinct - sometimes it doesn't work.
This is the code that works inside the class:
////////////////////////////
On Error Resume Next
For Each zz As Control In Controls
For Each zzz As Control In zz.Controls
For Each zzzz As Control In zz.Controls
AddHandler zzzz.MouseMove, AddressOf ControlMouseMov e
Next
AddHandler zzz.MouseMove, AddressOf ControlMouseMov e
Next
AddHandler zz.MouseMove, AddressOf ControlMouseMov e
Next
End Sub
Private Sub ControlMouseMov e(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs)
sender.Cursor.c urrent = CurrentCursor
End Sub
///////////////////////
I'd like to move the top part (not the handeler) to my library.
I suppose it would be great if the event (MouseMove) was also a variable but
don't have the slightest idea how to do that.
Thanks
"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message
news:ev******** ******@TK2MSFTN GP12.phx.gbl...
Its a bit more complicated than that really.
Your library code needs to know the event type it is going to handle, and
you need to tell it the address of your delegate function which will
handle it. In order to do this, the function being called will need to know the
reference to the instantiated object ( WithEvents ) which is must handle.
So you must pass it the control reference for which you want the event
handled for.
Public MyHandlerAdd( ByVal myControl as System.Windows. Forms.Control )
AddHandler Control.MouseMo ve, AddressOf MyHandler
End Sub
Public Sub MyHandler( ByVal Sender as Object, e as System.MouseEve ntArgs )
'// Do something here
End Sub
This all seems find and dandy, until you realise that you need reference
in the handling sub to the sender ( Which is actually an instance of this
class not the control ).
OHM ( Terry Burns )
I need to create a library sub that adds event handlers to a control.
Public Shared Sub AddEvent(ByVal qq As Control, By?? ControlMouseMov e
As ??)
So I need to pass the address of the handler or equivalent so that I
can
AddHandler qq.MouseMove, AddressOf ControlMouseMov e
In the callee class which also contains ControlMouseMov e