How to change mouse position in WPF

I generated a .cur file to use in my WPF application, the default position is the upper left corner, and I want to set it to the center.

I found topics here that help solve this problem by installing HotSpot s where you can do things like this:

 public static Cursor CreateCursorNoResize(Bitmap bmp, int xHotSpot, int yHotSpot) { IntPtr ptr = bmp.GetHicon(); IconInfo tmp = new IconInfo(); GetIconInfo(ptr, ref tmp); tmp.xHotspot = xHotSpot; tmp.yHotspot = yHotSpot; tmp.fIcon = false; ptr = CreateIconIndirect(ref tmp); return new Cursor(ptr); } 

The problem is that in WindosForms. In WPF, the Cursor class constructor does not accept IntPtr ; it accepts only Stream or String (file path).

How can I achieve this in WPF and is there any other way to do this?

+5
source share
1 answer

As @Kami mentioned, I had to apply the same logic mentioned in this thread in my .CUR file, and it worked.

0
source

Source: https://habr.com/ru/post/1200933/


All Articles