在WPF中强制鼠标沿特定轴移动

3

当用户按住左键时,如何强制鼠标沿着特定轴线移动?我希望用户能够沿着X轴移动鼠标,而在Y轴上任何移动都将被“取消”。

谢谢 Eden

1个回答

1

请查看此链接:http://social.msdn.microsoft.com/Forums/en/wpf/thread/9b07abce-bb32-4cd1-9ae5-d34973d5cc95

链接内容如下:

public partial class MouseOperations 
{ 
    [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "SetCursorPos")]   
    [return:System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]    
    public static extern bool SetCursorPos(int X, int Y); 
} 

你需要从Mouse.MouseMove事件处理程序中调用该方法。

MouseOperations.SetCursorPos(xAxisPosition,0);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接