【问题标题】:how can set animated cursors (.ANI). to cursor?如何设置动画光标(.ANI)。光标?
【发布时间】:2010-05-25 07:16:21
【问题描述】:

如何设置动画光标 (.ANI)。光标?

【问题讨论】:

标签: c#


【解决方案1】:

Here 是一个很好的例子,在一些包装类中使用 p/invoke。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;

public class Form1 : Form
{

  public Form1() {
        InitializeComponent();
    try
    {
      this.Cursor = AdvancedCursors.Create(Path.Combine(Application.StartupPath, "blob.ani"));
    }
    catch (Exception err)
    {
      MessageBox.Show(err.Message);
    }
  }

  private void InitializeComponent()
  {
    this.SuspendLayout();

    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Text = "Form1";
    this.ResumeLayout(false);
  }


  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}

public class AdvancedCursors
{

  [DllImport("User32.dll")]
  private static extern IntPtr LoadCursorFromFile(String str);

  public static Cursor Create(string filename)
  {
    IntPtr hCursor = LoadCursorFromFile(filename);
    
    if (!IntPtr.Zero.Equals(hCursor))
    {
      return new Cursor(hCursor);
    }
    else
    {
      throw new ApplicationException("Could not create cursor from file " + filename);
    }
  }
}

编辑:从外部资源复制代码以防止链接失效

【讨论】:

    猜你喜欢
    • 2017-07-25
    • 1970-01-01
    • 1970-01-01
    • 2014-10-09
    • 2019-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-29
    相关资源
    最近更新 更多