在C#中使用自定义光标 [英] Using a Custom Cursor in C#

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

问题描述

再次问好,CodeProject

另一个,这一次

我正在尝试为我的表单应用程序创建自定义光标

即不使用默认的但.cur文件,

我将myCur.cur添加到我的项目中,

然后我还将Build Action设置为Embedded Resource,同时尝试设置为资源

这是我尝试的代码示例:

  ///   TRY Number I 
光标mycur = new 光标(GetType(),< span class =code-string> myCur.cur
this .Cursor = mycur
/// TRY Number 2
光标mycur = new 光标(GetType(),Application.StartUpPath + @ \myCur.cur
.Cursor = mycur
/// TRY Number 3
光标mycur = new 光标(Application.StartUpPath + @ \ myCur.cur
this .Cursor = mycur
/// TRY Number 4
光标mycur = new 光标( myCur.cur
< span class =code-keyword> this
.Cursor = mycur



对于Try Number I,2我收到以下错误:

 NullReferenceException未处理
参数名称:Stream



对于尝试号码3,4

无效的图像格式



其中光标在Window上完全正常工作s

任何帮助将不胜感激.............



~Sids123

解决方案

以下是该怎么做:



创建一个* .resx文件。在添加到项目的资源节点上,选择添加现有文件并添加现有的有效游标文件。它会将文件添加到您的项目中(查看其属性:它们将被正确设置)并将在资源文件中添加对该文件的引用。这样,您的文件将不会被复制到输出目录,但它将嵌入到可执行模块中。



现在,如何使用它。查看放置在C#文件中的自动生成的代码作为资源解决方案资源管理器节点的子注释。在编辑器中打开此文件。查找与光标文件名相同或接近的静态属性的名称。看看声明:你会看到如何使用它。



-SA


你需要处理所有异常并为Cursor图像提供有效的图标文件。

看看这篇文章,这也将为您提供压缩格式的示例代码



[ ^ ]



如果你觉得这个答案有用,请相应评分。



干杯,

Kushagra

Hello Again, CodeProject
Another one, this time
I am trying to create a custom cursor for my forms application
i.e not using the default ones but .cur files,
I added myCur.cur to my project,
then I also set the Build Action to "Embedded Resource", Also tried to set it to "Resource"
Here's the code samples I tried :

///TRY Number I
Cursor mycur = new Cursor(GetType(),"myCur.cur")
this.Cursor = mycur
///TRY Number 2
Cursor mycur = new Cursor(GetType(),Application.StartUpPath + @"\myCur.cur")
this.Cursor = mycur
///TRY Number 3
Cursor mycur = new Cursor(Application.StartUpPath + @"\myCur.cur")
this.Cursor = mycur
///TRY Number 4
Cursor mycur = new Cursor("myCur.cur")
this.Cursor = mycur


For Try Number I,2 I get the following error:

NullReferenceException was Unhandled
Parameter Name : Stream


For try number 3,4

Invalid Image Format


where as the cursor works completely fine on Windows
Any Help would be appreciated.............

~Sids123

解决方案

Here is what to do:

Create an *.resx file. On the resource node added to your project, choose "Add existing file" and add existing valid cursor file. It will add the file to your project (look at its properties: they will be set correctly) and will add a reference to the file in the resource file. This way, your file won't be copied to output directory, but it will be embedded in the executable module.

Now, how to use it. Look at the auto-generated code placed in a C# file as a child note to your resource Solution Explorer node. Open this file in a editor. Look for the name of the static property identical or close to your cursor file name. Look at the declaration: you will see how to use it.

—SA


You need to handle all the exception and provide a valid icon file for the Cursor image.
Have a look at this article and this would also provide you with a sample code in zipped format

[^]

If you find this answer helpful please rate it accordingly.

Cheers,
Kushagra


这篇关于在C#中使用自定义光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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