鼠标拖动到与InputSimulator目标
问题描述:
我需要拖动一个WPF元素并放入另一个WPF目标元素。我一直在我的测试代码中使用InputSimulator进行所有键盘交互。但是没有发现有关使用InputSimulator拖动鼠标的任何事情。任何有关这方面的见解?鼠标拖动到与InputSimulator目标
答
您可以使用Mouse Class中的本机编码的ui方法。喜欢的东西,
编辑每个操作请求:
// Determine drop coordinates dynamically
Point dropDestinationPoint = controlYouWanttoDropOn.GetClickablePoint();
// Add some buffer to avoid possible clicking over the edges - Optional
dropDestinationPoint.X += 5;
dropDestinationPoint.Y += 5;
Mouse.StartDragging(controlYouWantToDrag);
Mouse.StopDragging(controlYouWanttoDropOn, dropDestinationPoint);
您也可以尝试,并获得直通BoundingRectangle属性点和它玩。
我曾经想过,但我在这里有一个问题。 dropDestinationPoint.X - 你如何得到这个坐标?如果说屏幕的分辨率发生变化,那么脚本不会失败? – Reema
它会,你可以动态地获得积分。更新了答案! –
这是否适合你!? –