[英]C# / Windows Forms - How can I determine if someone is currently “Dragging”? (not in DragOver event)
Assuming that I'm in a function that is called in a Timer on in Windows Forms class... how can I tell if the user is currently attempting to "Drag" something? Assuming that I'm in a function that is called in a Timer on in Windows Forms class... how can I tell if the user is currently attempting to "Drag" something?
example:例子:
public void SomeMethod()
{
// This doesn't exist of course :)
if (Mouse.IsDragging) ...
}
EDIT: I should specify that I know that I can override DragEnter and DragLeave to set my own private variable... but I'm asking/looking for a '.Nety' solution if one exists.编辑:我应该指定我知道我可以覆盖 DragEnter 和 DragLeave 来设置我自己的私有变量......但如果存在的话,我正在询问/寻找一个“.Nety”解决方案。
Easy:简单的:
bool mDragging;
...
mDragging = true;
DoDragDrop("test", DragDropEffects.All);
mDragging = false;
Universal:普遍的:
public static bool IsDragging()
{
StackFrame[] frames = new StackTrace(false).GetFrames();
foreach (StackFrame frame in frames)
{
System.Reflection.MethodBase mb = frame.GetMethod();
if (mb.Module.Name == "System.Windows.Forms.dll" && mb.Name == "DoDragDrop")
return true;
}
return false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.