|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Adding keydown event handlerThe sub declaration look like this: sub AddGotFocus(myTextBox as TextBox, GotFocusEvent as System.EventHandler) AddHandler myTextBox.GotFoucs, GotFocusEvent end sub I call this sub using AddGotFocus(text1,addressof Gotfocus). This works without any problem. When I try to do the same for the KeyDown and MouseDown event, Eg. sub AddKeyDown(myTextBox as TextBox, KeydownEvent as System.EventHandler) AddHandler myTextBox.KeyDown, KeydownEvent I get this error here: Value of type system.eventhandler cannot be converted to system.windows.forms.keyeventhandler end sub sub AddMOuseDown(myTextBox as TextBox, MousedownEvent as System.EventHandler) AddHandler myTextBox.Mousedown, MousedownEvent I get this error here: Value of type system.eventhandler cannot be converted to system.windows.forms.keyeventhandler end sub Can someone please help? TIA Young Young wrote:
> sub AddKeyDown(myTextBox as TextBox, KeydownEvent as As the message says, you have to pass a KeyEventHandler.> System.EventHandler) > AddHandler myTextBox.KeyDown, KeydownEvent > I get this error here: Value of type system.eventhandler cannot be > converted to system.windows.forms.keyeventhandler > > end sub If this is all the method does, I wonder why you need a method. You can execute Addhandler in the caller instead of calling a method that executes Addhandler. Armin Hi Armin,
Thanks for your reply. How do I pass in a KeyEventHandler? I created a sub and just pass it in like Address of SubName. The sub that receives this is declared as MyEvent As System.EventHandler. There's no System.KeyEventHandler. I've a lot of forms so this is easier for me. Otherwise I've to do it "locally" on each form. I also passed in other EventHandler - text got focus, lost focus etc. Young Show quoteHide quote "Armin Zingler" <az.nospam@freenet.de> wrote in message news:%23Ur037P5JHA.1420@TK2MSFTNGP04.phx.gbl... > Young wrote: >> sub AddKeyDown(myTextBox as TextBox, KeydownEvent as >> System.EventHandler) >> AddHandler myTextBox.KeyDown, KeydownEvent >> I get this error here: Value of type system.eventhandler cannot be >> converted to system.windows.forms.keyeventhandler >> >> end sub > > As the message says, you have to pass a KeyEventHandler. > > If this is all the method does, I wonder why you need a method. You can > execute Addhandler in the caller instead of calling a method that executes > Addhandler. > > > > Armin Young wrote:
> Hi Armin, No, but there is KeyEventHandler. Full name is > > Thanks for your reply. > > How do I pass in a KeyEventHandler? > > I created a sub and just pass it in like Address of SubName. > > The sub that receives this is declared as MyEvent As > System.EventHandler. There's no System.KeyEventHandler. System.Windows.Forms.KeyEventHandler. (Using "symbol search" (Alt+F12 here) quickly finds it) > I've a lot of forms so this is easier for me. Otherwise I've to do it Yes, but why is> "locally" on each form. I also passed in other EventHandler - text got > focus, lost focus etc. AddGotFocus(text1,addressof Gotfocus) better than Addhandler text1.gotfocus, addressof Gotfocus ? View chars less typing can't be the reason because you have to write the additional AddGotFocus, AddkeyDown etc. subs. Armin It seems you have two choices.
You could change the declarations for the arguments from System.EventHandler to System.Windows.Forms.KeyEventhandler, and adjust your event handling code to process the different fields of the argument. Or you could create a new event with the argument list you need (System.Eventhandler) and raise that event in the corresponding event handlers for the control (KeyDown and MouseDown in this example) and create a common handler for this event instead of the control events. The first option is simpler, but requires adding a handler for every event you want to use. The second enables you to use a much smaller number of handlers, but you need to add code for each control to raise the common events. Show quoteHide quote "Young" <young10***@hotmail.com> wrote in message news:4a278b51$1@dnews.tpgi.com.au... >I create a sub that will add event handlers to text boxes. > > The sub declaration look like this: > > sub AddGotFocus(myTextBox as TextBox, GotFocusEvent as > System.EventHandler) > > AddHandler myTextBox.GotFoucs, GotFocusEvent > > end sub > > I call this sub using AddGotFocus(text1,addressof Gotfocus). This works > without any problem. When I try to do the same for the KeyDown and > MouseDown event, Eg. > > sub AddKeyDown(myTextBox as TextBox, KeydownEvent as System.EventHandler) > > AddHandler myTextBox.KeyDown, KeydownEvent > I get this error here: Value of type system.eventhandler cannot be > converted to system.windows.forms.keyeventhandler > > end sub > > sub AddMOuseDown(myTextBox as TextBox, MousedownEvent as > System.EventHandler) > > AddHandler myTextBox.Mousedown, MousedownEvent > I get this error here: Value of type system.eventhandler cannot be > converted to system.windows.forms.keyeventhandler > > end sub > > Can someone please help? > > TIA > Young > |
|||||||||||||||||||||||