Question Global Events?

RafC

New member
Joined
Oct 8, 2008
Messages
3
Programming Experience
Beginner
Hey,
Im new to vb.net.
I would like to be able to "catch" an event regardless of which controll currently has focus.
For example: I would like to catch mouseup and keypress every time one of those occurs without having to write a procedure with many statements like:
handles button1.mouseup, button2.mouseup, button3.mouseup etc.

in short, is there a statement or a way to "say" something like handles "all.mouseup" ?

If not, does any one have any suggestions on how I can solve this in a more efficient manner?

thanks.
 
You can handle it at the form level with a form event.
Private Sub frmMain_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp

End Sub
 
I tried that.
If I click on a button on the form, the code in my mouseup event procedure is not run if I use "handles me.mouseup"

for some reason if the mouse down event occurs on a different control (command button, text box etc) the mouseup event must be associated with that control. I think it is becuase during the mousedown the control gets focus.

so once again: is there a way to catch mouseup or keypress events regardless of focus. Isn't there some sort of hierarchy that first detects the mouse up event THEN associates it with a control? or is it the other way around?

Thanks.
 
I see. What you want would be like the KeyPreview property for the form that enables catching keyboard events. I don't believe there is anyway to do that for mouse events except building your own handler. You can also use addHandler to assign an event handler.
 
Ok
what if i were to make some sort of arraylist with all the controls that are contained in my form. and i wrote handles arraylist.mouseup or perform some sort of iteration.

what I'm trying to do is to take the focus away from any button / control that i press. anyone have any suggestions on how to do this?

thanks.
 
With a IMessageFilter class you can catch the low level windows messages when they first arrive to the application. See Application.AddMessageFilter Method in help. The 513-514 range in that sample corresponds to windows messages WM_LBUTTONDOWN, WM_LBUTTONUP and WM_LBUTTONDBLCLK, this will give you some indication what to research.
 
Back
Top