Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How to set mouse position in WPF C#?

c# wpf wpf c# mouse set mouse position error dll method

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 SickHeadPro

SickHeadPro

    CC Lurker

  • New Member
  • Pip
  • 8 posts

Posted 18 March 2015 - 12:59 PM

Hello,

 

I have been using:

private void SetPosition(int a, int b)
{
    SetCursorPos(a, b);
}

[DllImport("User32.dll")]
private static extern bool SetCursorPos(int X, int Y);

in WPF to set the mouse position, however for me this only works when I set the .NET framework to version 3.5, but I really need this to work when I am using the .NET frame work version 4.5.1.

 

I get this error when I use the above code: http://puu.sh/gFRgD/2febc03cb9.png

 

Any help would be great.

 

Thanks.



#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 19 March 2015 - 05:02 PM

It doesn't seem a SetCursorPos exception but a Xaml one.

Of course, in there, the resources are loaded in the order that they are read, so my guess is: either the error is not related to setcursor, or you are setting the cursor on a position whose resource haven't been loaded yet.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download