记录鼠标行为

Posted on 2019-01-17 14:58  努力成长静待花开  阅读(184)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  MouseEventArgs类的Button属性    //用来获取按下的是那个键

  public MouseButtons Button {get;}

  Left  //左键  None   //未曾    XButton1  //拓展按钮1

  Right  //右键  Middle  //中键    XButton2  //拓展按钮2

实现代码:

        private void textBox1_MouseDown(object sender, MouseEventArgs e)
        {
            string str = textBox1.Text;
            if (e.Button == MouseButtons.Left)
                str += "鼠标左键被按下 ";
            if(e.Button==MouseButtons.Right)
                str += "鼠标右键被按下 ";
            if (e.Button == MouseButtons.Middle)
                str += "鼠标中键被按下 ";
            textBox1.Text = str;
        }