windows 处理拖动时是否可以更改鼠标光标(来自 DragOver 事件)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6175408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to change mouse cursor when handling drag (from DragOver event)?
提问by Marek
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.
这已经为拖出实现了,使用在GiveFeedback
事件处理程序中设置的自定义光标(DoDragDrop
在将项目拖出我们的应用程序时引发)。将GiveFeedbackEventArgs
允许我们指定UseDefaultCursors
属性-设置为false,使我们可以覆盖光标。
However, the DragOver
event handler argument, which is the equivalent of GiveFeedback
, does not have UseDefaultCursors
property and changing the cursor from there does not have any effect.
但是,与DragOver
等效的事件处理程序参数GiveFeedback
没有UseDefaultCursors
属性,并且从那里更改光标没有任何效果。
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.
拖动操作源自我们的应用程序外部。(对于应用内拖动,它使用GiveFeedback
事件。
How to change the cursor when receiving a drag? Is this even possible/feasible?
接收拖动时如何更改光标?这甚至可能/可行吗?
回答by Barrakoda
void Form1_GiveFeedback(object sender, GiveFeedbackEventArgs e) {
e.UseDefaultCursors = false;
}
回答by CodeGuru
回答by Jakob M?ll?s
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;
}
回答by Pedery
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.
希望这将为您指明正确的方向。