Search code examples
vb.netdrag-and-dropcustom-cursor

DragDrop - Change Cursor to USER-DEFINED CustomCursor


Maybe I have missed something obvious. Currently I am using the feedback interrupt to change the cursor to one of the Windows supplied cursors (thanks to being put on the right track by Hans Passant in answer to a previous request for help - thanks).

Instead of using the pre-packaged cursors, is it possible to use my own custom-cursor (icon), and if so - are there any rules re size etc., or can I use something like a png/jpg etc.. ?

Regards,

Oliver


Solution

  • Yes, no problem. But it has to be a cursor, it can't be an image.

    You can turn an image into an icon with Bitmap.GetHicon() method and pass that to the Cursor class constructor. It does however a very poor job on images that contain a lot of colors. The color mapping algorithm is miserable, in general that's something that's hard to do well. It is best to use a good graphics program. Check my answer here for a trick to use text as a cursor, using the same technique.