gpt4 book ai didi

c# - 如何在 wpf 中用本地镜像更改光标?

转载 作者:太空宇宙 更新时间:2023-11-03 14:05:07 25 4
gpt4 key购买 nike

我正在尝试加载本地镜像并将其用于光标。为此,我必须将图像流发送到 Cursor(Stream cursorStream) 构造函数。

    var res = Application.GetResourceStream(new Uri("pack://application:,,,/MyProj;component/Images/delete-icon.png"));

this.Cursor = new Cursor(res.Stream);

问题是我总是得到这个异常

ReadTimeout = (res.Stream).ReadTimeout threw an exception of type 'System.InvalidOperationException'
WriteTimeout = (res.Stream).WriteTimeout threw an exception of type 'System.InvalidOperationException'

我应该怎么做?

最佳答案

光标需要 .cur 文件类型。还要确保资源文件夹中的文件将其构建操作设置为资源

示例:如果我项目中的以下文件夹有 .cur 光标文件 --> component/Resource/Images/BusyCursor.cur

我使用下面的代码和 this 控件的光标更改。

StreamResourceInfo sri = System.Windows.Application.GetResourceStream(
new Uri("/<projectname>;component/Resource/Images/BusyCursor.cur", UriKind.RelativeOrAbsolute));

this.Cursor = new Cursor(sri.Stream);

关于c# - 如何在 wpf 中用本地镜像更改光标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9530717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com