Setup cursor cho ứng dụng

Source
Visual C# Code:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9. using System.IO;
  10.  
  11. public class Form1 : Form
  12. {
  13.  
  14.   public Form1() {
  15.         InitializeComponent();
  16.     try
  17.     {
  18.       this.Cursor = AdvancedCursors.Create(Path.Combine(Application.StartupPath, "blob.ani"));
  19.     }
  20.     catch (Exception err)
  21.     {
  22.       MessageBox.Show(err.Message);
  23.     }
  24.   }
  25.  
  26.   private void InitializeComponent()
  27.   {
  28.     this.SuspendLayout();
  29.  
  30.     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  31.     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  32.     this.ClientSize = new System.Drawing.Size(292, 266);
  33.     this.Text = "Form1";
  34.     this.ResumeLayout(false);
  35.   }
  36.  
  37.  
  38.   [STAThread]
  39.   static void Main()
  40.   {
  41.     Application.EnableVisualStyles();
  42.     Application.Run(new Form1());
  43.   }
  44.  
  45. }
  46.  
  47. public class AdvancedCursors
  48. {
  49.  
  50.   [DllImport("User32.dll")]
  51.   private static extern IntPtr LoadCursorFromFile(String str);
  52.  
  53.   public static Cursor Create(string filename)
  54.   {
  55.     IntPtr hCursor = LoadCursorFromFile(filename);
  56.    
  57.     if (!IntPtr.Zero.Equals(hCursor))
  58.     {
  59.       return new Cursor(hCursor);
  60.     }
  61.     else
  62.     {
  63.       throw new ApplicationException("Could not create cursor from file " + filename);
  64.     }
  65.   }
  66. }