how to Make the Mouse Freeze c#

前端 未结 6 667
眼角桃花
眼角桃花 2021-01-19 19:33

i want the mouse to freez (cant move) when mouse down thanks

6条回答
  •  无人及你
    2021-01-19 19:53

    It's possible, Windows has a dedicated API for it, BlockInput(). Be sure to save all your work when you experiment with it, it is rather effective. You may need to reboot your machine, the thing your user will do when you use it in a program. Here's a sample Windows Forms form that uses it, it needs a button and a timer:

    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
            timer1.Interval = 3000;
            timer1.Tick += new EventHandler(timer1_Tick);
            button1.Click += new EventHandler(button1_Click);
        }
        private void button1_Click(object sender, EventArgs e) {
            timer1.Enabled = true;
            BlockInput(true);
        }
        private void timer1_Tick(object sender, EventArgs e) {
            timer1.Enabled = false;
            BlockInput(false);
        }
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool BlockInput(bool block);
    }
    

提交回复
热议问题