Rajesh Kumbhar

Rajesh Kumbhar

  • NA
  • 269
  • 1.4k

how to disable mouse action outside Windows form

Sep 16 2021 11:38 AM

I am trying below code but it is not working . Please help me I am new in c#.net

 

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        Rectangle BoundRect;
        Rectangle OldRect = Rectangle.Empty;

        private void EnableMouse()
        {
            Cursor.Clip = OldRect;
            Cursor.Show();
            Application.RemoveMessageFilter((IMessageFilter)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(530, 530, 200, 200);
            Cursor.Clip = BoundRect;
            Cursor.Hide();
            Application.AddMessageFilter((IMessageFilter)this);
        }
    }


Answers (2)