Get Cursor Position on Wpf

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool GetCursorPos(out POINT lpPoint);

    [StructLayout(LayoutKind.Sequential)]
    public struct POINT {
      public int X;
      public int Y;

      public POINT(int x, int y) {
        this.X = x;
        this.Y = y;
      }
    }

    POINT p;
      if(GetCursorPos(out p) && myEllipse != null) {
        myEllipse.Margin =
    new Thickness(Convert.ToDouble(p.X - 70),
    p.Y - 25, p.X + 70, p.Y + 25);
      }

* This source code was highlighted with Source Code Highlighter.

Advertisements
This entry was posted in Snippets, Wpf. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s