views:

1123

answers:

4

Well, as the title says, how can I set an image or anything else as the mouse cursor. I know you can use the built in ones that are part of the Cursors class, but I was wondering if there's a way to use your own image (preferably without P/Invoke, but either way is fine.)

EDIT: I guess I didn't explain what I wanted clearly enough. I don't have any .cur files (are they easy to create?), I want to know if there's a way to take an image from disk (or wherever) and use that as the cursor. Ultimatley what I'd like would be to do something like this:

myForm.Cursor = new Cursor(Image.FromFile("foo.jpg"));

Possible?

+1  A: 

First add the custom cursor to your project then it's pretty simple:

Cursor myCursor = new Cursor("custom.cur");

Then just assign it to your controls

someControl.cursor = myCursor
Jared
+5  A: 

At the simplest, you just use:

form.Cursor = new Cursor(path);

But there are overloads to load from other sources (an unmanaged pointer, a raw stream, or a resx).

Marc Gravell
+2  A: 

If you want some more information on how to create your own cursor resources then there is a good tutorial here. You should create your cursor file and embed it as a resource in your executable - easy in Visual Studio. This is tidier and more efficient than loading it from a separate file. You can then load it directly using the Cursor constructor that takes a resouce name.

Stu Mackellar
A: 

In addition to what mentioned above, you can do this:

Mouse.OverrideCursor = Cursors.Arrow;

and Cursors can be : AppStarting Arrow ArrowCD Cross Hand Help Pen UpArrow or others.

paradisonoir