Click outside of form detection
-
Ok, I'm sure there's an easy answer to this... I just can't figure this out? DUH.. I have a main application (form) that brings up a different form. What I want to do, is to detect ANY click while this new form is up. If the click is OUTSIDE the bounds of this form, I want to perform some action (such as closing the form). Any ideas?
-
Ok, I'm sure there's an easy answer to this... I just can't figure this out? DUH.. I have a main application (form) that brings up a different form. What I want to do, is to detect ANY click while this new form is up. If the click is OUTSIDE the bounds of this form, I want to perform some action (such as closing the form). Any ideas?
If you're just wanting to monitor mouse messages for a short period of time (such as for a popup/menu), you can set the form's Capture property to
true
. This will redirect all mouse messages to your window. After the first click outside of your window, the mouse capture will be released and you won't get any more mouse messages from outside your form. Other windows, including child windows on your form, will not recieve any mouse messages while your form has the mouse capture. If you need child windows to recieve mouse messages, release the capture when the mouse moves within your form's bounds. Note that it is bad practice to capture the mouse for more than just a brief period/operation, as the mouse pointer is a shared system resource."A people that values its privileges above its principles soon loses both."
-- Dwight D. Eisenhower -
Ok, I'm sure there's an easy answer to this... I just can't figure this out? DUH.. I have a main application (form) that brings up a different form. What I want to do, is to detect ANY click while this new form is up. If the click is OUTSIDE the bounds of this form, I want to perform some action (such as closing the form). Any ideas?
Well, a maybe simpler way could be to add an event handler for the Leave or Deactivate event. The moment the user clicks outside your form it's losing focus and this event can be caught and handled. But you have to remember that when you close the form yourself then these events are generated as well IIRC. And that switching the window by using Alt-TAB for example also triggers this event, not just mouse clicks. Regards, mav
-
Ok, I'm sure there's an easy answer to this... I just can't figure this out? DUH.. I have a main application (form) that brings up a different form. What I want to do, is to detect ANY click while this new form is up. If the click is OUTSIDE the bounds of this form, I want to perform some action (such as closing the form). Any ideas?