在C#中禁用鼠标的移动和点击干脆 [英] Disabling mouse movement and clicks altogether in c#

查看:1039
本文介绍了在C#中禁用鼠标的移动和点击干脆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在工作中,我是一个教练。我设立教训,教人如何做的东西没有鼠标...你见过的人点击登录文本框中键入,拿鼠标,单击密码,输入自己的密码,然后再取鼠标点击连接按钮下方的?

At work, i'm a trainer. I'm setting up lessons to teach people how to "do stuff" without a mouse... Ever seen people click "login" textbox, type, take the mouse, click "password", type their password, then take the mouse again to click the "connect" button beneath ?

所以我会教他们如何做的一切,没有鼠标(其中包括许多其他的东西,当然)

So i'll teach them how to do all that without a mouse (among many other things, of course)

在课程结束后,我要让他们通过某种考试。

At the end of the course, i'll make them pass a sort of exam.

所以我M建设中,我目前的形式一定simili,现实生活中的例子,以填补在一个小的基于向导的应用程序,但我希望通过编程禁用自己的鼠标,而他们做这个测试。

但是,进一步的向导,我得让他们再次使​​用自己的鼠标

However, further in the wizard, i'll have to let them use their mouse again.

有一个 - 可能是简单的 - - ?办法只有禁用鼠标了一会儿,后来就重新启用

Is there a -- possibly easy -- way to just disable the mouse for a while, and re-enable it later on?

我在C#2.0,在VC#2K5编程,如果该事项

I'm on C# 2.0, programming under VC# 2k5, if that matters

推荐答案

请您的形式实施 IMessageFilter

然后将以下代码添加到窗体:

Then add the following code to the form:

    Rectangle BoundRect;
    Rectangle OldRect = Rectangle.Empty;

    private void EnableMouse()
    {
        Cursor.Clip = OldRect;
        Cursor.Show();
        Application.RemoveMessageFilter(this);
    }
    public bool PreFilterMessage(ref Message m)
    {
        if (m.Msg == 0x201 || m.Msg == 0x202 || m.Msg == 0x203) return true;
        if (m.Msg == 0x204 || m.Msg == 0x205 || m.Msg == 0x206) return true;
        return false;
    }
    private void DisableMouse()
    {
        OldRect = Cursor.Clip;
        // Arbitrary location.
        BoundRect = new Rectangle(50, 50, 1, 1); 
        Cursor.Clip = BoundRect;
        Cursor.Hide();
        Application.AddMessageFilter(this);
    }  

这将隐藏光标,让这个不能移动它并禁用右和左mousebuttons

This will hide the cursor, make it so that they can't move it and disable the right and left mousebuttons.

这篇关于在C#中禁用鼠标的移动和点击干脆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆