How can I change the mouse cursor image?

谁说胖子不能爱 提交于 2021-02-08 07:36:21

问题


I need to change the cursor image. Whenever the mouse is over my form I need to load my own image from a local path. I am using version 1.1 of the .NET framwork.

Here is what I have tried:

Cursor = new Cursor(GetType(),  Application.StartupPath+ "\\windowfi.cur");

But this throws an exception:

Value cannot be null.
Parameter name: dataStream


回答1:


Cursor class has a constructor that takes in cur file path as a parameter. Use that. Like this:

this.Cursor = new Cursor("<your_cur_file_path");



回答2:


This should probably work:

Cursor.Current = new Cursor(GetType(), Application.StartupPath+ @"\windowfi.cur"); 

or

Cursor.Current  = new Cursor(GetType(), Application.StartupPath+ "\\windowfi.cur");

Note the use of @ string literal and the \ escape character above to be able to use the backslash character correctly in the path to the cursor's icon. As well as the Current property of the Cursor class.




回答3:


It looks like you're using the wrong overload for the cursor constructor. If you want to use a file path, use the constructor overload that just takes a string. You are using the overload that takes a type and a string. That overload gets an embedded resource.



来源:https://stackoverflow.com/questions/1175870/how-can-i-change-the-mouse-cursor-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!