Load a cursor from a resource in C#

[cursor]

Sometimes it’s useful to use a non-standard cursor in a program. This example explains how you can load a cursor from a cursor file included as a project resource.

To add a cursor file to the project’s resources, open the Project menu and select Properties. On the Resources tab, open the Add Resource dropdown and select Add Existing File. Select the file and click Open.

Now use code similar to the following to load the cursor resource at run time.

// Load the cursors from resources.
private void Form1_Load(object sender, EventArgs e)
{
    pictureBox1.Cursor =
        new Cursor(new MemoryStream(Properties.Resources.addlink));
    pictureBox2.Cursor =
        new Cursor(new MemoryStream(Properties.Resources._4way03));
    pictureBox3.Cursor =
        new Cursor(new MemoryStream(Properties.Resources.bullseye));
}

The MemoryStream class is in the System.IO namespace, so you can make it easier to use by adding the following statement at the top of the file.

using System.IO;


Download Example   Follow me on Twitter   RSS feed   Donate




This entry was posted in files, graphics and tagged , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *