Using Custom WinForms Cursors

Is there a way to use a custom cursor in winforms?

There seems to be no choice. But when I try to manually add the cursor as a resource and then call it from the code, it says that it cannot convert from byte type [] to Cursor.

+6
c # winforms cursor
source share
4 answers

Adding a custom icon to the cursor in C #:

Add icon file to project resources (for example: Processing.ico)

And in the image properties window of the "Build Action" to "Embedded" switch

Cursor cur = new Cursor(Properties.Resources.**Imagename**.Handle); this.Cursor = cur; Ex: Cursor cur = new Cursor(Properties.Resources.Processing.Handle); this.Cursor = cur; 
+8
source share

From the MSDN documentation in the Cursor class (with minor fixes):

 // The following generates a cursor from an embedded resource. // To add a custom cursor, create or use an existing 16x16 bitmap // 1. Add a new cursor file to your project: // File->Add New Item->Local Project Items->Cursor File // 2. Select 16x16 image type: // Image->Current Icon Image Types->16x16 // --- To make the custom cursor an embedded resource --- // In Visual Studio: // 1. Select the cursor file in the Solution Explorer // 2. Choose View->Properties. // 3. In the properties window switch "Build Action" to "Embedded" // On the command line: // Add the following flag: // /res:CursorFileName.Cur,Namespace.CursorFileName.Cur // // Where "Namespace" is the namespace in which you want to use // the cursor and "CursorFileName.Cur" is the cursor filename. // The following line uses the namespace from the passed-in type // and looks for CustomCursor.MyCursor.Cur in the assemblies manifest. // NOTE: The cursor name is case sensitive. this.Cursor = new Cursor(GetType(), "MyCursor.Cur"); 
+4
source share

I used the LoadCursorFromFile() method from User32.dll. There are many examples on the Internet for this.

OR

The side for the Cursor type also has an IO.Stream overload. Load byte[] into a MemoryStream and feed this to the new Cursor .

+1
source share

After adding the file to the resources in the image properties window: switch the Build Action to the Embedded Resource and write in your code:

 "name of control".Cursor = new System.Windows.Forms.Cursor(Properties.Resources."name of image".Handle); 
0
source share

All Articles