[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Load a cursor from a resource in C#

[Load a cursor from a resource in C#]

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 the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.