0

I need to write event handlers for tracking mouse movements, but the mouse-down and mouse-up events are not related to any Control object. What is the generic way to do this? On researching this question on StackOverflow, I found a lot of information about mouse events related to specific controls, such as the PictureBox, but I don't find any on C# generic mouse listeners. I did find a much older question, but it wasn't related to C#.

DrKoch
  • 9,556
  • 2
  • 34
  • 43
Su Llewellyn
  • 2,660
  • 2
  • 19
  • 33
  • I noticed this in msdn article: Invoking an event can only be done from within the class that declared the event. So how would I listen for mouse movements not related to a specific form. (This is a winforms application.) Here is the link to the MSDN article: https://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx – Su Llewellyn Apr 03 '15 at 16:18
  • I think I might have found a related answer in this StackOver flow question: http://stackoverflow.com/questions/18316693/screen-capture-target-area-of-the-desktop – Su Llewellyn Apr 03 '15 at 16:23
  • Not clear what you are asking. What do you mean by "not related"? – DrKoch Apr 03 '15 at 16:24
  • Hi, DrKoch. I mean that I don't want my mouse movements to be specific to the Windows Form, but to the screen. I was trying to capture a region of the screen. – Su Llewellyn Apr 03 '15 at 16:25
  • You need a hook to track the mouse if it is not interacting with your UI. Not directly covered by the framework, the pinvoke for SetWindowsHookEx is widely available. You don't actually need a hook to do this, find sample code in [this post](http://stackoverflow.com/a/3124252/17034). – Hans Passant Apr 03 '15 at 16:35

0 Answers0