#831 – Embedding a Cursor in Your Project as a Resource

If you have a custom cursor that your application uses, you can load it at run-time from an external file.  But this requires that you distribute the cursor file with your application.  To avoid distributing the .cur file, you can embed this file into your project as a resource.

First, add the .cur file to your project and set its Build Action to Resource.

831-001

831-002

831-003

831-004

To load the cursor at run-time, you use the Application.GetResourceStream method, which returns a StreamResourceInfo object.  You can then use the Stream property of this object to create the cursor.  (You’ll need a using statement for the System.Windows.Resources namespace).

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            StreamResourceInfo sriCurs = Application.GetResourceStream(
                new Uri("captain-america-arrow.cur", UriKind.Relative));

            this.Cursor = new Cursor(sriCurs.Stream);
        }

831-005

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #831 – Embedding a Cursor in Your Project as a Resource

  1. Pingback: Dew Drop – May 30, 2013 (#1,557) | Alvin Ashcraft's Morning Dew

  2. Jan Piekarski says:

    thanks so much. my English is not(hing) so… just thanks again

Leave a comment