Detect if ANY control is clicked inside a form, regardless of the container
-
Hey all, is there a way to detect if ANY control is clicked inside a form? The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way? Cheers, Dennis
-
Hey all, is there a way to detect if ANY control is clicked inside a form? The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way? Cheers, Dennis
-
I feel sorry for this poster. He was told to post here, and he's only done what he was told.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
I feel sorry for this poster. He was told to post here, and he's only done what he was told.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
Hey all, is there a way to detect if ANY control is clicked inside a form? The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way? Cheers, Dennis
Dennis Bork wrote:
The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way?
False, anything that inherits from Control[^]. See Richards'[^] answer for a recursive method that loops all controls, and hook 'em up to a single event-handler. The 'sender' argument would tell you what control was clicked.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]
-
Hey all, is there a way to detect if ANY control is clicked inside a form? The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way? Cheers, Dennis
Hello Dennis Bork, With regards to your question, http://stackoverflow.com/questions/986529/how-to-detect-if-the-mouse-is-inside-the-whole-form-and-child-controls-in-c Hope this helps! Best of Luck! With Kind Regards,
April Comm100 - Leading Live Chat Software Provider
-
Hey all, is there a way to detect if ANY control is clicked inside a form? The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way? Cheers, Dennis
-
Hey all, is there a way to detect if ANY control is clicked inside a form? The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way? Cheers, Dennis
Hi, One other (slightly heavy handed) possibility is to override the Windows Procedure in your form. You can then intercept all the windows messages it receives, and filter down to the mouse events. eg:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } protected override void WndProc(ref Message m) { base.WndProc(ref m); } }
You can get an enum containing all the windows message constants here: [^]