Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Changing the cursor's clicking/pointing position?

So the default cursor is the "Arrow" cursor and the top-left of the arrow (where the point is) is the part that clicks or interacts with other controls. How can I change the pointing part to say the tail of the arrow?

What I have is a custom cursor (a bitmap image) which is a circle at 16x16 size and I want the very center of it to be the pointer. I have another custom arrow-like cursor that points downward-left also 16x16 and I want the bottom-left corner of the cursor to be the pointer. I think there's a property in the cursor class for this but I'm not sure what it's called.

like image 740
Jack Avatar asked Jul 23 '11 02:07

Jack


2 Answers

This is actually specified in the CUR file format.

The CUR file format is an almost identical image file format for non-animated cursors in Microsoft Windows. The only differences between these two file formats are the bytes used to identify them and the addition of a hotspot in the CUR format header; the hotspot is defined as the pixel offset (in x,y coordinates) from the top-left corner of the cursor image where the user is actually pointing the mouse.

Programs that can edit CUR files generally allow you to specify the hot spot. More information can be found in this question.

like image 101
CodeNaked Avatar answered Oct 24 '22 17:10

CodeNaked


What you want can't be done through code. I wanted do the same thing but it's not possible. In fact, the Cursor class has a property called HotSpot, which is the point that you want change. However this property is readonly. The only way to change this is at file loading (on a .cur file, I suggest you using Paint .net with Cursor and icons plugin (search over the web) to edit cursor). An important thing: the cursor must be a file and not a resource or things like that (must be a file on the file system) to load it. Remember it, I had bad times testing in other ways.

The idea that I have in mind is: edit cursor file just when you need to change the hotspot, however this require for you writing an api that allows you to change the hotspot on a cursor file. I obviusly don't know how this file is built so you must continue from here.

Hope this was useful

like image 37
Francesco Belladonna Avatar answered Oct 24 '22 17:10

Francesco Belladonna