开发者

Is it possible to change mouse cursor when handling drag (from DragOver event)? [duplicate]

This question already has answers here: Can I choose a custom image for C# Windows Application Drag Drop functions? (2 answers) Closed 9 years ago.

We need to display a feedback to the user when he drags-in items into our application. Our client prefers this feedback to be in form of a custom cursor.

This is already implemented for drag-out, using a custom cursor that is set in GiveFeedback event handler (raised by DoDragDrop when dragging items out of our app). The GiveFeedbackEventArgs allows us to specify UseDefaultCursors property - setting this to false allows us to override the cursor.

However, the DragOver event handler argument, which is the equivalent of GiveFeedback, does not have UseDefaultCursors property and c开发者_开发问答hanging the cursor from there does not have any effect.

Sample (this has no effect):

private void browser_DragOver(object sender, DragEventArgs e) {
  Cursor.Current = Cursors.WaitCursor;
}

The drag operation originates from outside our app. (for in-app drag, it works using the GiveFeedback event.

How to change the cursor when receiving a drag? Is this even possible/feasible?


void Form1_GiveFeedback(object sender, GiveFeedbackEventArgs e) {
    e.UseDefaultCursors = false;
}


Yes, you must implement a COM interfaces (IDragSourceHelper and IDropTargetHelper). Take a look HERE.


Would this suffice?
This code will change the mouse pointer by adding a [+] sign next to it.

private void Form_DragOver(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Copy;
}


We've addressed a whole range of drag-drop issues here:

Drag and Drop between Instances of the same Windows Forms Application

Hopefully this will point you in the right direction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜