Capturing the mouse

In c#, I need to capture the mouse so that I know the location the mouse outside the form.  

Is there a way to capture the mouse so that the mouse events go back to my form, even when the mouse is not over my form

Thanx...


Answer this question

Capturing the mouse

  • Torbjorn

    I would use the static member Cursor.Position, which returns the screen coordinates of where the mouse is at that particular time.

    Alternately, you can look at Control.MousePosition.

    Hope this helps.

    -Ari

  • jdcal

    Well my friend, I think you posted to the wrong board;)

    Luckily, you found an expert.  Capturing mice is easy!  Just get a trap and some cheese and the mouse is as good as gone!!!  (Unless, he's the one from "Mouse Hunt")


    OK!  On the serious side...
    To get the point OUTSIDE of the form, use the Windows API.

      [DllImport("user32.dll")]
      static extern int GetCursorPos( out System.Drawing.Point pnt);

  • Jonface

    One way you could do this is to create another invisible form, maximize it, and handle the events from there.

    <A href="http://msdn.microsoft.com/vbasic/using/columns/adventures/default.aspx pull=/library/en-us/dnadvnet/html/vbnet11122002.asp">This MSDN article</a> should provide the needed details on how to do this.


  • Capturing the mouse