Detecting mouse click

snarfblam

Ultimate Contributor
Joined
Jun 10, 2003
Messages
2,097
Location
USA
I have a control that I want to be hidden when the user clicks outside of it. How can I detect such a mouse click?
 
i think you must explore the mousepointer.x or y, and with the window position and size of it... but i dont know...
 
IngisKahn said:
If the control receives focus then you can use the LostFocus event.

Well... that's what I tried. The problem is that my form is full of pictureboxes, which react to mouse events, but don't take focus.
 
DiverDan said:
One thought would be to have your form detect the mouse click then send a delegated message via a public properity to the control.

The control would need to be hidden not only when the user clicks on the form, but when he clicks on any other control, even those that can't accept focus, as well as when the user clicks anywhere outside the form.

I wanted my control to act very much like a context menu, in that when you click a button, it is displayed, allows him to make a selection (from a grid, thought, rather than a list of menuitems), then the control would disappear. And, like a menu, if the user clicks anywhere else on the screen, I want to hide the control and get it out of his way.

What I did is show a context menu with a single, owner drawn item. I do my drawing to the menuitem instead of a control, and when the user clicks, I take the mouse coordinates, and calculate where in the menu the user clicked. This method, however, gives me less control with respect to mouse events, and is less reliable.
 
Back
Top