Mouse position on extended displays

你。 提交于 2021-02-17 05:54:25

问题


I could not find anything on this particular problem, so here it goes!

I am interested in changing the position of the mouse cursor programmatically.

Cursor.Position = new Point(x, y);

works as expected using a single monitor. However, when I plug in a second one and choose to extend the desktop, changing the cursor's coordinates only works relative to the main screen.

So, does anyone know how to tell the cursor that I want to move to a different screen?


回答1:


Get the width and height of your required screen and move the cursor relative to it

int width=Screen.AllScreens[1].Bounds.Width;
int height=Screen.AllScreens[1].Bounds.Height;
Cursor.Position=new Point(width-x,height-y);


来源:https://stackoverflow.com/questions/18725003/mouse-position-on-extended-displays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!