【问题标题】:can I "cancel" mouse move and make the mouse cursor remain visible but in place?我可以“取消”鼠标移动并使鼠标光标保持可见但在原位吗?
【发布时间】:2009-11-11 10:50:47
【问题描述】:

我正在使用角手柄实现形状调整。在某些情况下,鼠标握住手柄的某些移动是不合法的,例如如果它实际上将其扩展到控制边界之外。因此,在这种情况下,我想做的是以编程方式“取消”鼠标在飞行中的移动,以便鼠标停留在静止手柄矩形的范围内。我该怎么做?

【问题讨论】:

    标签: c# .net mouse


    【解决方案1】:

    尝试使用 ClipCursor api 函数 (http://msdn.microsoft.com/en-us/library/ms648383(VS.85).aspx)

    下面是一个例子:

    [DllImport("user32.dll")]
    static extern bool ClipCursor(ref RECT lpRect);
    
    public struct RECT
    {
        public int Left;
        public int Top;
        public int Right;
        public int Bottom;
    
        public RECT(int left, int top, int right, int bottom)
        {
            Left = left;
            Top = top;
            Right = right;
            Bottom = bottom;
        }
    }
    
    private void button7_Click(object sender, EventArgs e)
    {
        RECT rect = new RECT(Left, Top, Width, Bottom);
        ClipCursor(ref rect);
    }
    

    问候

    【讨论】:

    • 只有在一个窗口中应用才有效,因为一旦应用了换到另一个窗口就失效了,有没有办法在所有窗口都应用?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    相关资源
    最近更新 更多