Search code examples
c#bitmapcursorpanelembedding

Embedding Cursors Causes Panel to Crash


If I use this code my panel (Canvas) crashes:

Assembly asm = Assembly.GetExecutingAssembly();
        using (Stream resStream = asm.GetManifestResourceStream("Pie_X.blank.cur"))
        {
            CanvasCursor = new Cursor(resStream);
            resStream.Close();
        }
        using (Stream resStream = asm.GetManifestResourceStream("Pie_X.hand.cur"))
        {
            HandCursor = new Cursor(resStream);
            resStream.Close();
        }

How ever this code does not cause it to crash:

Assembly asm = Assembly.GetExecutingAssembly();
        using (Stream resStream = asm.GetManifestResourceStream("Pie_X.blank.cur"))
        {
            CanvasCursor = new Cursor(resStream);
            resStream.Close();
        }
        using (Stream resStream = asm.GetManifestResourceStream("Pie_X.blank.cur"))
        {
            HandCursor = new Cursor(resStream);
            resStream.Close();
        }

blank.cur is a cursor I got off of the internet, and hand.cur is a cursor I made in photoshop with a cursor plugin. Why will my cursor not load, I have tried reducing the size to 30x30 pixels and it still crashes.


Solution

  • Check to be sure that hand.cur is in the same Pie_X namespace that blank.cur is in, and that you have set its Build Action to Embedded Resource.

    Also make sure you can edit it with the built-in VS2010 resource editor (to validate the format).