Detect both left and right mouse click at the same time?

前端 未结 6 1830
礼貌的吻别
礼貌的吻别 2020-12-17 01:51

I\'m remaking windows Minesweeper (from XP) and something they had included was that if you click a number with as many flags as it\'s number with the left and right mouse b

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-17 02:33

    Create a class boolean variable for the left and right button defaulted to false. When the mouse down event fires set the variable to true and check if both are true. When the mouse up fires set the variable to false.

        public bool m_right = false;
        public bool m_left = false;
    
        private void MainForm_MouseDown(object sender, MouseEventArgs e)
        {
            m_objGraphics.Clear(SystemColors.Control);
    
            if (e.Button == MouseButtons.Left)
                m_left = true;
            if (e.Button == MouseButtons.Right)
                m_right = true;
    
            if (m_left == false || m_right == false) return;
            //do something here
        }
    
        private void MainForm_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                m_left = false;
            if (e.Button == MouseButtons.Right)
                m_right = false;
         }
    

提交回复
热议问题