Cursors

  • Thread starter Thread starter Martijn Mulder
  • Start date Start date
M

Martijn Mulder

I am looking for a tutorial for creating and using custom cursors in a .NET
application
 
Hello Martijn,

Cursor class has the number of overloaded constructors, one of which takes
the IntPtr, where you can specify the handle of your custom bitmap image
returned from Bitmap.GetHicon

MM> I am looking for a tutorial for creating and using custom cursors in
MM> a .NET application
MM>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Hi Martjin,

Here is a short tutorial on how to create and utilize a custom Cursor from
within VS 2005:

1. In VS 2005 (and earlier versions of VS.NET as well, AFAIK) you can create a
cursor by adding a new file to a project and selecting Cursor as the file
type. Create one now and name it, "MyFirstCursor.cur". There is a hot-spot
tool that you can use when designing your cursor. The hot-spot tool button
contains an icon of a solid black arrow pointing to what appears to be a
spark. Use the tool to set the pixel that will be the actual coordinates used
for mouse events.

2. Add a resource file to the project and name it "MyCursors.resx".

3. With the "MyCursors.resx" file open in the designer, select from the
drop-down the view type named, "Files". (The default will probably be
"Strings").

4. Open the Solution Explorer and drag the "MyFirstCursor.cur" file into the
white-space of the "MyCursors.resx" designer.

The .resx file will be compiled into the project's assembly as an embedded
resource. The embedded resource will contain the contents of the
"MyFirstCursor.cur" file. The "MyFirstCursor.cur" file itself is only project
content and will not be contained in the assembly.

5. Use the following code to create a Cursor object for your custom cursor,
"MyFirstCursor.cur":

Cursor cursor;

using (System.IO.MemoryStream stream =
new System.IO.MemoryStream(MyCursors.MyFirstCursor))
{
cursor = new Cursor(stream);
}

6. Set the Form's Cursor:

form.Cursor = cursor;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top