.net下实现鼠标左右两个按键齐击,就好像扫雷下面的效果

发现.net没有鼠标齐击的事件,就写了一个,大家看看,有更好更简单的方法不妨写下,让大家也参考一下吧

没有什么技术含量,主要是看两个按键释放的间隔时间,如果间隔很近就认为是“齐击”了

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        DateTime mLeft = DateTime.Now,
                 mRight=DateTime.Now;
       
        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mLeft = DateTime.Now;
                TimeSpan t1 = mLeft.Subtract(mRight);
                if (t1.Milliseconds < 100)
                    MessageBox.Show("鼠标齐击了!");
            }
            else if (e.Button == MouseButtons.Right)
            {
                mRight = DateTime.Now;
                TimeSpan t1 = mRight.Subtract(mLeft);
                if (t1.Milliseconds < 100)
                    MessageBox.Show("鼠标齐击了!");
            }

        }

    
    }
}

posted on 2010-06-29 21:07  我是大超  阅读(218)  评论(0)    收藏  举报

导航