|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
KeyUp + KeyDown Event Handlerhandler but can't find how to determine which event was fired - Private Sub ListBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _ Handles ListBox1.KeyUp, ListBox1.KeyDown If e.KeyValue = Keys.PageDown Or e.KeyValue = Keys.PageUp Or e.KeyValue = Keys.End Or e.KeyValue = Keys.Home Then 'If User "Pressed" key (KeyDown) then do something... 'If User "Released" key (KeyUp) then do something else... End If End Sub Apart from duplicating the code in the individual KeyUp and KeyDown Events, does anyone know how to determine which action triggered the event handler in this case? ShaneO There are 10 kinds of people - Those who understand Binary and those who don't. ShaneO wrote:
Show quoteHide quote > I would like to handle the KeyUp & KeyDown events in the same event Have you tried writing a common method, then having the KeyUp and KeyDown> handler but can't find how to determine which event was fired - > > Private Sub ListBox1_KeyUp(ByVal sender As Object, ByVal e As > System.Windows.Forms.KeyEventArgs) _ > Handles ListBox1.KeyUp, ListBox1.KeyDown > > If e.KeyValue = Keys.PageDown Or e.KeyValue = Keys.PageUp Or e.KeyValue > = Keys.End Or e.KeyValue = Keys.Home Then > > 'If User "Pressed" key (KeyDown) then do something... > 'If User "Released" key (KeyUp) then do something else... > > End If > > End Sub > > Apart from duplicating the code in the individual KeyUp and KeyDown > Events, does anyone know how to determine which action triggered the > event handler in this case? events call it? Something like this... Protected Sub CommonKeyHandler( _ ByVal sender As Object, _ ByVal e As System.Windows.Forms.KeyEventArgs, _ ByVal SentBy As Byte) (insert code here) End Sub Private Sub Button1_KeyDown( _ ByVal sender As Object, _ ByVal e As System.Windows.Forms.KeyEventArgs) CommonKeyHandler(sender, e, 0) End Sub Private Sub Button1_KeyUp( _ ByVal sender As Object, _ ByVal e As System.Windows.Forms.KeyEventArgs) CommonKeyHandler(sender, e, 1) End Sub -- Gregory Gadow techb***@serv.net > Thanks for your reply Gregory.> Have you tried writing a common method, then having the KeyUp and KeyDown > events call it? Something like this... > > -- > Gregory Gadow > techb***@serv.net > > I have thought about doing that, however that would require entries in 3 separate Event Handlers. (1 for KeyUp, 1 for KeyDown & 1 for the final Event Handler). I guess I really just like to have my code as compact as possible and by having only one Handler to cover the two events it would help me in that regard. Maybe my desire isn't achievable with these events? ShaneO There are 10 kinds of people - Those who understand Binary and those who don't. ShaneO wrote:
Show quoteHide quote > I would like to handle the KeyUp & KeyDown events in the same event How are you duplicating code if you want and if statement seperating the > handler but can't find how to determine which event was fired - > > Private Sub ListBox1_KeyUp(ByVal sender As Object, ByVal e As > System.Windows.Forms.KeyEventArgs) _ > Handles ListBox1.KeyUp, ListBox1.KeyDown > > If e.KeyValue = Keys.PageDown Or e.KeyValue = Keys.PageUp Or e.KeyValue > = Keys.End Or e.KeyValue = Keys.Home Then > > 'If User "Pressed" key (KeyDown) then do something... > 'If User "Released" key (KeyUp) then do something else... > > End If > > End Sub > > > Apart from duplicating the code in the individual KeyUp and KeyDown > Events, does anyone know how to determine which action triggered the > event handler in this case? > > ShaneO > > There are 10 kinds of people - Those who understand Binary and those who > don't. two. You can call the same sub from both if you want the two to runsome of the same code, but not all. Chris Chris wrote:
>> Thanks Chris for your reply.>> Apart from duplicating the code in the individual KeyUp and KeyDown >> Events, does anyone know how to determine which action triggered the >> event handler in this case? >> > > How are you duplicating code if you want and if statement seperating the > two. > > You can call the same sub from both if you want the two to runsome of > the same code, but not all. > > Chris I suppose I should have written my example as - If e.KeyValue = Keys.PageDown Or e.KeyValue = Keys.PageUp Or e.KeyValue = Keys.End Or e.KeyValue = Keys.Home Then 'Do Some Stuff.... 'Do More Stuff.... .. .. .. 'If User "Pressed" key (KeyDown) then do something... 'If User "Released" key (KeyUp) then do something else... End If Please see my reply to Gregory Gadow regarding the option of creating a common handler. ShaneO There are 10 kinds of people - Those who understand Binary and those who don't.
For each
Lock statement in C#, Is there an equivalent in VB.NET? Calculate elapsed time Multiple threads using a shared printer resource Help needed on creating Shared Directory progress bar convert text to access mdb Structured files in VS 2005 halt application flow until condition is met halt application flow until condition is met |
|||||||||||||||||||||||