change hotspot of a custom cursor

时间秒杀一切 提交于 2019-12-25 04:59:08

问题


I'm using a custom cursor that I loaded in this way:

Bitmap bit = new Bitmap(path);
cur = new Cursor(bit.GetHicon());
Cursor.current = cur;

my bitmap is a 44x58 png and the mouse hot spot is not exactly where I want to be. I looked for a property to change the mouse hot spot but the only one I found is readable-only (cur.Hotspot). What I need to do for change its coordinates?

Thanks


回答1:


In Visual Studio, open the cursor file or resource in the image editor and select the Hotspot Tool from the toolbar. Then click on the new hotspot and save the file. AFAIK there is no way to set the hotspot via the .NET API, but there are options via the WIN32 API, as demonstrated in the links in the others' comments.




回答2:


At the end I simply decide to hide the mouse cursor and draw a bitmap at the hotspot coordinates. Too much complicated the solution suggested.

cursor = new Bitmap(path);

in MouseMove event:

ex = e.X - offx //the x offset of the hotspot
ex = e.X - offy //the y offset of the hotspot

then paint as last drawing element the bitmap at the (ex,ey) coordinates.



来源:https://stackoverflow.com/questions/11526351/change-hotspot-of-a-custom-cursor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!