Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use a custom mouse Cursor in a .NET application?

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?

like image 388
BFree Avatar asked Jan 28 '09 22:01

BFree


People also ask

How do I use a custom mouse cursor?

Step 1: Navigate to the Mouse properties window as we did earlier. Step 2: Select the Pointers tab. Step 3: To select a custom cursor for the highlighted individual icon, click Browse. Step 4: That will open the default cursors folder, where hundreds of different cursor options are available.

How do I change the cursor in Visual Studio?

Open Control Panel | Appearance and Personalization | Personalization | Change mouse pointers.

What is the use of cursor in C#?

A cursor in Windows is an icon that is displayed when you move a mouse, a pen, or a trackball. This code shows how to apply and manage cursors in your Windows applications. A cursor in Windows is an icon that is displayed when you move a mouse, a pen, or a trackball.


1 Answers

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).

like image 87
Marc Gravell Avatar answered Nov 14 '22 22:11

Marc Gravell