Results 1 to 6 of 6

Thread: catch mouse!

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    catch mouse!



    I know I can get the position of the mouse cursor when it is hovering/moving over the active form however how can I capture the mouse even when the mouse pointer/cursor is off the form?

    is this possible?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: catch mouse!

    The Cursor class has the static member "Position" which is a Point.

    so, something like this:

    Code:
    Using System.Windows.Forms;
    
    // ....
    MessageBox.Show("Cursor is at (" + Cursor.Position.X.ToString() + "," + Cursor.Position.Y.ToString() + ").");
    hope this helps!
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: catch mouse!

    oh I already had that. Actually I meant, how can I get feedback all the time? in other words, some how catching the mouse move event even if its off the form?

    I found another NOT so good solution - stick a timer on the label and on every millisecond get the cursor position and that works.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: catch mouse!

    Use a mouse hook.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: catch mouse!

    explain a bit more please - in depth.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: catch mouse!

    Register a mouse hook for a window and that window will receive system-wide mouse messages in its window message loop (WndProc). Override the standard WndProc method to receive the messages.

    If you do a quick Google, like this, you will find examples of that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width