title: C# Embed Custom Cursor
body: <p>I've spent ages working on this and I've almost got it. However, there is one final problem I am suffering from and it's really starting to get under my skin. I can't embed my custom cursor into my application...</p>
  
  <p>I'm currently using the following method to change the cursor to the custom one I have in the solution explorer. It's "MyCursor.cur", it's an embedded resource and I have set Copy to Output Directory to Copy if Newer. This is the code I'm using to set the cursor:</p>
  
  <pre><code>public static Cursor ActuallyLoadCursor(String path)
  {
      return new Cursor(LoadCursorFromFile(path));
  }
  [System.Runtime.InteropServices.DllImport("user32.dll")]
  private static extern IntPtr LoadCursorFromFile(string fileName);
  </code></pre>
  
  <p>and in my form's constructor:</p>
  
  <pre><code>Cursor = ActuallyLoadCursor("MyCursor.cur");
  </code></pre>
  
  <p>This is the only thing that has worked for me to load the cursor and use it in my application. This, however, copies the cursor to the same folder as the program. I have searched online for hours with no luck. Is there any way I can do this without it being copied and without a thousand lines of unnecessary code?</p>
  
  <p>Here's other solutions I have tried which have failed for me:</p>
  
  <pre><code>using (MemoryStream ms = new MemoryStream(Properties.Resources.MyCursor))
  {
      Cursor = new Cursor(ms);
  }
  
  Cursor = new Cursor(Assembly.GetExecutingAssembly().GetManifestResourceStream("My_Namespace.MyCursor.cur"));
  </code></pre>
  
  <p>These resulted in:</p>
  
  <blockquote>
    <p>Image format is not valid. The image file may be corrupted.
    Parameter name: stream</p>
  </blockquote>