本文介绍了如何从Resources.resx显示自定义光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,
我在Visual Studio 2008中创建了一个项目.然后将一个名为"arrow.cur"的文件放入"Resources.resx"中.我想在
中使用arrow.cur
Hi friends,
I created a project in Visual Studio 2008. Then I put a file called "arrow.cur" into "Resources.resx". I want to use arrow.cur in
Form1_Load(object sender, EventArgs e)
方法.如何显示此光标?
我试图编写这样的代码,但没有成功:
method. How can I show this cursor?
I tried to write code like this, but it didn''t work:
private void Form1_Load(object sender, EventArgs e)
{
byte[] cur = global::Demo.Properties.Resources.arrow;
MemoryStream stream = new MemoryStream();
stream.Write(cur, 0, cur.Length);
Cursor cursor = new Cursor(stream);
this.Cursor = cursor;
}
如果您知道解决方案,请帮助我.
谢谢!
If you know the solution, please help me.
Thanks!
推荐答案
private static Cursor ReadFromResource(byte[] res)
{
MemoryStream stream = new MemoryStream(res);
Cursor result = new Cursor(stream);
stream.Close(); // important
}
然后,
And then,
this.Cursor = ReadFromResource(Test.Properties.Resources.Arrow);
这篇关于如何从Resources.resx显示自定义光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!