0

I have a kinect application and I want change the cursor for an image, but without affect the features like click, drag etc that works now.

I tried use this code, but its not the goal, because, the image appears, but I can't click, drag etc. Somebody have any ideas?

public void showImageInsteadCursor(){

        form frm = new form();
        picturebox pb = new picturebox() { image = image.fromfile(@"c:\users\user\desktop\img.bmp") };
        frm.cursor = new cursor(((bitmap)pb.image).gethicon());
        frm.windowstate = formwindowstate.maximized;
        frm.transparencykey = frm.backcolor = system.drawing.color.turquoise;
        frm.formborderstyle = formborderstyle.none;
        frm.showdialog();
}
Magic
  • 1
  • 4

1 Answers1

0

You can't create a cursor directly from a bitmap. I wonder that you see anything at all! A cursor differs from a bitmap in one single, important aspect: A cursor also contains the information, which of the pixels of the bitmap is the "tip" of the cursor, so to say: The pixel where the click appears. For an arrow cursor, this is the tip of the arrow, for a hand cursor it's the tip of the straight finger. Bitmaps are lacking this information, that's why use need a cursor resource (or file or stream), see here for more details.

Heinz Kessler
  • 1,610
  • 11
  • 24
  • Thank you for explanation. So what you recommend in my case? And is it possible to hide the cursor and show just one image? The cursor will be there but is hidden or the image are above cursor. is it possible? You understand? – Magic Mar 08 '17 at 14:58
  • Honestly, it is a long time ago that I created a cursor file (.CUR), and Visual Studio has no cursor editor. This link leads to an article that describes how to use icons (.ICO) instead of cursors (.CUR): [link](https://www.codeproject.com/Tips/60379/Use-Icons-for-cursors-not-CUR). If that doesn't help, get back here or write me at Heinz.Kessler[at]web.de – Heinz Kessler Mar 08 '17 at 17:24
  • Heinz Kessler, thank you for the answer but it isn't what I want, I don't want change cursor, I want add image above cursor for example and it is possible to click and do the things that the cursor does. The trick is the cursor are hidden just this, and appear an image. You have an idea how I can do this? – Magic Mar 08 '17 at 17:32
  • So you want a normal cursor that works as always, but you want an image above it that moves together with the cursor? If the cursor and the image don't overlap, and if the image is always the same, then you can still use my approach in that you unite your image and the cursor into one bitmap that acts like a cursor. – Heinz Kessler Mar 09 '17 at 07:00
  • If your result shall look more like what you see if you drag and drop in Windows Explorer, the read [this post](http://stackoverflow.com/questions/16384903/moving-a-control-by-dragging-it-with-the-mouse-in-c-sharp). There they drag a picture box inside a form. If you change their code and use a form instead, you will have what you need. You must open the form with myForm.Show() so that it is modeless. Put a PictureBox inside the form and make sure the form has no border and give it the same size as the PictureBox, then you can drag it around together with the cursor. – Heinz Kessler Mar 09 '17 at 07:06
  • Heinz Kessler thank you. Yes, what you said above is right, I want unite your image and the cursor into one bitmap that acts like a cursor. Regard your last comment, you saw my code in the post? I think that I already did what you said, but I can move the image, but the cursor don't appear and don't work, just move. Can you help me? – Magic Mar 09 '17 at 09:21
  • Magic, your code does not exactly match what I said. – Heinz Kessler Mar 09 '17 at 18:29
  • I've written a small working example, please [download](http://cloud1.zoolz.co.uk/s-ydjGlbWC). I hope this is what you intended. Call pbForm.Show() and see. Maybe the form won't stay on top of your other windows, needs more work on this... – Heinz Kessler Mar 09 '17 at 19:10