问题
How can i change the mouse pointer to an image when clicked on the image in c#?
回答1:
The question is vague/unclear but perhaps you want to change the system cursor (not just your application)? Here is a link to the pinvoke info for SetSystemCursor. Be warned this is considered bad form.
回答2:
This MSDN article explains how you would do it with WPF. Just change their drop-down to a OnClick for the image you're interested in.
You could likely also hook in to an OnClick event in WinForms too, but I don't have an example readily available for that. If you're doing WinForms and not WPF, edit your question to specify!
You can create your own custom cursor with:
yourCursor = new Cursor(someImageStream);
Here's a way I verified to load a custom cursor. This certainly works and combines some of the information from your own comment as well as the blog article I linked below.
var image = (Bitmap)Bitmap.FromFile(@"c:\cursorImage.bmp");
IntPtr ptr = image.GetHicon();
var handle = new SafeFileHandle(ptr, true);
var yourCursor = System.Windows.Interop.CursorInteropHelper.Create(handle);
Cursor = yourCursor;
A more detailed explaination of loading images for use in a custom cursor is provided at this blog article which may be more robust, but looks to be more than you need considering the above.
回答3:
this.Cursor = Cursors.WaitCursor;
Handle click event of control in which you display image. In this event handler change cursor propery of control to desired one - you can of course construct you own Cursor object see Cursor.
来源:https://stackoverflow.com/questions/7323851/how-to-change-the-mouse-pointer-to-an-image-when-clicked-on-it-in-c-sharp