多彩光标 [英] Colorful Cursor

查看:76
本文介绍了多彩光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将鼠标光标更改为彩色光标,但是光标类不支持动画光标.
我为此找到了一个循序渐进"指南,但是(根据本文的回复)看来,我是唯一没有成功的指南.链接为: http://leifw.wickland.net/2006/08/loading-color-cursor-in-net-20.html
我所做的是在资源中添加了一个.cur文件,并在课堂上拍了灰线(来自上面的链接).
以下代码未编译,错误是"WriteAllBytes"函数应获取byte []变量而不是位图...因此,我添加了将位图转换为字节数组的代码行.
但这仍然无济于事,在运行代码后,我得到以下错误:传递给Cursor的Win32句柄无效或类型错误."
这就是我要运行的内容:
----------------------------------------------
//此行已添加到using部分:using System.Runtime.InteropServices;
[DllImport("user32.dll")]
静态外部IntPtr LoadCursorFromFile(string lpFileName);
私有Cursor LoadColorHandCursor()
{
图片image = Properties.Resources.hand2;
MemoryStream流=新的MemoryStream();
image.Save(stream,System.Drawing.Imaging.ImageFormat.Bmp);
Byte []个字节= stream.ToArray();
字符串路径= Path.GetTempFileName();
File.WriteAllBytes(path,bytes);
光标手=新光标(LoadCursorFromFile(path));
File.Delete(路径);
回手
}
Cursor.Current = LoadColorHandCursor();
----------------------------------------------
我不知道出了什么问题,可能是我不完全理解上面链接中的解释.
如果有人知道我的代码有什么问题,或有任何其他想法,它将对我有很大帮助.
p.s:如果此代码有效,则意味着我可以将任何图像文件用作源文件,并且该代码将其转换为彩色光标(不仅是.cur文件)?

在高级感谢中,

I''m trying to make the mouse cursor change into a colorful one, but the cursor class doesn''t support animated cursors.
I found a "step by step" guide for that, but it seems to be (by the replies of the article), that I''m the only one that didn''t succeed. The link is: http://leifw.wickland.net/2006/08/loading-color-cursor-in-net-20.html
What I did is added a .cur file to resources, and patsed the grey lines (from the link above) in my class.
The following code didn''t get compiled and the error was that the "WriteAllBytes" function should get a byte[] variable and not a bitmap... therefore I''ve added code lines that convert a bitmap to a bytes array.
But it still didn''t help, and after running the code I get the folowing error: "Win32 handle passed to Cursor is not valid or is the wrong type."
This is what I''m trying to run:
----------------------------------------------
//This line was added in the using section: using System.Runtime.InteropServices;
[DllImport("user32.dll")]
static extern IntPtr LoadCursorFromFile(string lpFileName);
private Cursor LoadColorHandCursor()
{
Image image = Properties.Resources.hand2;
MemoryStream stream = new MemoryStream();
image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
Byte[] bytes = stream.ToArray();
string path = Path.GetTempFileName();
File.WriteAllBytes(path, bytes);
Cursor hand = new Cursor(LoadCursorFromFile(path));
File.Delete(path);
return hand;
}
Cursor.Current = LoadColorHandCursor();
----------------------------------------------
I have no idea whats wrong, it could be I didn''t understand excactly what was explained to do in the link above.
If anyone knows whats wrong with my code, or has any other idea, it will really help me.
p.s: If this code works, it means I could use any image file as the source file, and the code converts it into a colorful cursor (not only .cur files)?

Thanks in advanced,

推荐答案

Tmuna写道:

图像image = Properties.Resources .hand2;

Image image = Properties.Resources.hand2;



我认为这就是问题所在.您链接到的文章的确在尝试使用字节数组以外的名称调用WriteAllBytes,并且他的在线示例已损坏.因此,很难弄清为什么有些人似乎认为他的解决方案有效.看起来应该可以正常工作.我建议将其分解.获取一个游标文件,并通过调用LoadCursorFromFile将其加载,如果可行,请尝试进行将游标放入资源中的下一步.




I assume this is where the problem is. The article you link to, is indeed trying to call WriteAllBytes with something other than a byte array, AND his online sample is corrupted. So, it''s hard to work out why some people seem to think his solution works. It looks like it should work, tho. I would suggest breaking it down. Get a cursor file and load it with the call to LoadCursorFromFile, and if that works, then try to take the next step of putting that cursor into your resources.


Tmuna写道:

ps:如果此代码有效,则表示我可以将任何图像文件用作源文件,并将代码转换为彩色光标(不仅是.cur文件)?

p.s: If this code works, it means I could use any image file as the source file, and the code converts it into a colorful cursor (not only .cur files)?



光标是具有两个重要区别的图像文件:

1-光标可以具有标记为透明的区域,也可以具有标记为反转其颜色的区域

2-光标包含告诉其光标在图像中的位置的数据.

您也许可以使用任何位图,这取决于它是否使光标自己决定了光标的尖端,如果文件没有告诉它.



A cursor is an image file with two important differences:

1 - a cursor can have areas marked as transparent, but also areas marked as inverting the color they are over

2 - a cursor contains data telling it where the tip of the cursor is in the image.

You may be able to use any bitmap, it depends on if it makes it''s own guess as to where the tip of the cursor is, if it''s not told by the file.


这篇关于多彩光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆