小编H. *_*din的帖子

在 WPF 中设置自定义光标图像热点

我正在尝试在 Cursor 上使用自定义图像,并使用这些代码做到了。

public static class cursorHelper
{

    public static Cursor vertical = new Cursor(Application.GetResourceStream(getFromResource("PenCADwpf", "Images/cursors/Vertical.ico")).Stream);
    public static Cursor horizontal = new Cursor(Application.GetResourceStream(getFromResource("PenCADwpf", "Images/cursors/Horizontal.ico")).Stream);
    public static Uri getFromResource(string psAssemblyName, string psResourceName)
    {
        Uri oUri = new Uri("pack://application:,,,/" + psAssemblyName + ";component/" + psResourceName, UriKind.RelativeOrAbsolute);
        return oUri;
    }
    public static ImageSource getImageSourceFromResource(string psAssemblyName, string psResourceName)
    {
        Uri oUri = getFromResource(psAssemblyName, psResourceName);

        return BitmapFrame.Create(oUri);
    }

}
Run Code Online (Sandbox Code Playgroud)

在代码中使用的是

    private void btnVerticalMullion_Click(object sender, RoutedEventArgs e)
    {
        this.Cursor = cursorHelper.vertical;
    }
Run Code Online (Sandbox Code Playgroud)

我的问题是光标的热点是左下角。我需要将其更改为图像的 0,0(左上角)点。请问有人可以帮助我吗?提前致谢,

c# wpf image cursor

1
推荐指数
1
解决办法
5417
查看次数

标签 统计

c# ×1

cursor ×1

image ×1

wpf ×1