我生成了一个 .cur
文件,用于在我的 WPF
应用程序中使用,鼠标指针默认位置是左上角,我想将其设置为中心。
我在这里找到了一些线程,可以通过设置 HotSpot
来解决这个问题,您可以执行类似以下操作的内容来完成:
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);
}
问题在于它位于WindowsForms中。在WPF中,Cursor类构造函数不接受IntPtr,它只接受Stream或String(文件路径)。
我该如何在WPF中实现这个,还有其他方法吗?
.ico
文件中获取.cur
光标。我已经有了一个.cur
格式的光标,我想找到类似于Windows Forms的解决方案,希望我解释得清楚。 - AymenDaoudi