Teststack.White Drag and Drop Problems

2.2k views Asked by At

I'm having trouble dragging a control to another control. I've had success in being able to select both controls but when I try to use:

Mouse.Instance.Location = dragControl.ClickablePoint;
Mouse.LeftDown();

Mouse.Instance.Location = dropControl.ClickablePoint;
Mouse.LeftUp();

The drag doesn't happen, the mouse moves. But the control stays in the initial spot.

I've also tried using:

Mouse.Instance.DragAndDrop(dragItem, dragItem.ClickablePoint, dropItem, dropItem.ClickablePoint);

Still no luck.

I was doing some experimentation and one point and got it to work, but I've lost track of the resource I found a workable solution in before (and I deleted my working code - lesson learned).

Any help would be appreciated!

Thanks in advance!

Update 6/15

Okay, so I've been hacking away at this some more. For some reason it seems like the control isn't actually being dragged. The mouse is moving, but the control isn't being moved with it.

1

There are 1 answers

4
Brandon Scriver On BEST ANSWER

Alright, I have no idea why White DragAndDrop functionality isn't working (or manually using leftDown, move, leftUp).

But I did find a solution.

Essentially I re-wrote the white drag and drop function with a delay between each step. So it looks like the following:

guiObject.Click();
Mouse.LeftDown();

var stepCount = 10;
var stepAmount = (float) (guiObject.ClickablePoint.Y - targetObject.ClickablePoint.Y)/stepCount;

for (var i = 0; i < stepCount; i++)
{
    Mouse.Instance.Location = new Point(Mouse.Instance.Location.X, Mouse.Instance.Location.Y - stepAmount);
    Thread.Sleep(75); // I played around with the values and 75 seems to work without being too slow
}

Mouse.LeftUp();

Hopefully this will help anyone else that might be having this problem. I don't know why I needed to force a delay, but it works.