Changing the mouse cursor on a pencil in the drawing panel

In my Winform application, I have a drawing panel.

When I move the cursor inside the drawing panel, the cursor should be changed to a pencil. How can I do this?

+4
source share
3 answers

There is no cursor in the cursor class called "Pencil", see the full list of cursors here:

Full list of cursors

However you can try custom cursors

Visual Studio allows you to create cursor files (.cur). The cursor file is a bitmap file with the extension .cur. To create a cursor file, right-click it and select Add New Item. After that, select the Cursor File item from the elements. This action will add a default Cursor1.cur file.

enter image description here

After adding the cursor file, you will be taken to the raster image editor, where you can change the bitmap using the drawing tools, as you can see

enter image description here

Now copy the Cursor1.cur file to the Debug or Release folder where your executable file is stored.

Once the file is saved, we can create a cursor from the cursor file using the following code snippet.

C # code:

this.Cursor = new Cursor(Application.StartupPath + "\\Cursor1.cur"); 

VB.NET Code:

 Me.Cursor = New Cursor(Application.StartupPath + "\Cursor1.cur") 
+1
source

Set the Control Cursor property with a pencil. It seems that this is not one of the options in the designer or one of the values ​​in the cursors, so you have to go this way as follows:

 Cursor pencil = new Cursor("Path to cursor Icon file"); Control.Cursor = pencil; 
+1
source

Source: https://habr.com/ru/post/1444725/


All Articles