【问题标题】:C# Winforms - change cursor icon of mouseC# Winforms - 更改鼠标的光标图标
【发布时间】:2011-02-23 13:04:36
【问题描述】:

如何将光标图标更改为桌面上通常显示的“忙碌图标”?如何设置动画文件 (.gif,.ani) 而不是光标?

【问题讨论】:

  • 请更正(使其更具体)问题并将您的 2 个答案也添加到其中。或者“@Carlos Loth”可能已经给出了正确答案?

标签: c# winforms mouse-cursor


【解决方案1】:

尝试执行以下操作:

System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

更多信息请访问Cursors Class documentation

Cursor 类不支持 GIF 文件或动画光标 (.ANI)。您可以加载自定义光标做

Cursor.Current = new Cursor("C:\\ic.cur");

也许您可以使用Microangelo 之类的工具将您的 GIF 文件转换为光标格式。另外,还有一个跟它相关的线程。

How do you convert a GIF into a CUR file?

【讨论】:

  • 那么,“C:\ic.gif”应该是“C:\ic.cur”吗?
【解决方案2】:

我有图片框的答案

Picturebox1.cursor = new cursor(Properties.Resources.CURSOR NAME.GetHicon());

【讨论】:

    【解决方案3】:

    还有简单的纯C#方式:

    System.Windows.Forms.Cursor cursor = null;      
    var info = System.Windows.Application.GetResourceStream(
            new Uri(@"pack://application:,,,/Resources/MyCursor.cur"));
    cursor = new System.Windows.Forms.Cursor(info.Stream);
    

    MyCursor.cur 必须作为资源包含在您的项目中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-16
      • 2013-09-04
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 2011-02-28
      相关资源
      最近更新 更多