tags:

views:

76

answers:

1

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.

+2  A: 

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;
    }
Hans Passant
Crazy - but good enough :) ... I wish I was able to use WPF on this project!
Timothy Khouri
this is crazy, but good thinking! +1 for that!
Peter Gfader