C#: Hide Mouse & Disable Mouse input

person Jason Huangfolder_openC#, Codelocal_offer, , , access_time April 23, 2010

To disable mouse input & hide mouse cursor:
– In your Form Class, implement the interface IMessageFilter

Use the following code:

//in class header

public partial class FrmInputPrompt : Form, IMessageFilter

// method for iMessageFilter & methods for disable/enable mouse.

        bool IMessageFilter.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;
        }
 
        public void EnableMouse()
        {
            Cursor.Clip = OldRect;
            Cursor.Show();
            Application.RemoveMessageFilter(this);
        }
 
        public void DisableMouse()
        {
            OldRect = Cursor.Clip;
            // Arbitrary location.
            BoundRect = new Rectangle(50, 50, 1, 1);
            Cursor.Clip = BoundRect;
            Cursor.Hide();
            Application.AddMessageFilter(this);
        }

Comment

  1. Hi!!

    this not turn to Disable the mouse input, only disappears the cursor,

    //[DllImport(“user32.dll”)]
    //public static extern void BlockInput(bool fBlockIt);

    im using this but no luck yet

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>