5

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

I found some threads here that help resolve that problem by setting the HotSpots, where you can do stuff 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 is in WindosForms. In WPF the Cursor class constructor doesn't accept a IntPtr, it accepts only a Stream or String (file path).

How can I achieve this in WPF and is there a whole other way to do it ??

Community
  • 1
  • 1
AymenDaoudi
  • 7,811
  • 9
  • 52
  • 84
  • 1
    possible duplicate of [Set Custom Cursor Image Hotspot in WPF](http://stackoverflow.com/questions/12447038/set-custom-cursor-image-hotspot-in-wpf) – Kami Aug 22 '14 at 16:19
  • @Kami that thread helps you get the `.cur` cursor from a `.ico` I already have it in a `.cur` format, I want to find a solution similar to the Windows Forms one, I hope I explained well – AymenDaoudi Aug 22 '14 at 16:31
  • That is what the linked answer does - please read it again. – Kami Aug 22 '14 at 18:37

1 Answers1

0

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

Community
  • 1
  • 1
AymenDaoudi
  • 7,811
  • 9
  • 52
  • 84