picture根据鼠标位置执行相应操作

this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);

 

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            Point aa = new Point(e.X, e.Y);
            Rectangle r1 = new Rectangle(0, 0, this.pictureBox1.Width, ((int)this.pictureBox1.Height/2));

 

            Rectangle r2 = new Rectangle(0, ((int)this.pictureBox1.Height / 2), this.pictureBox1.Width, ((int)this.pictureBox1.Height / 2));

            if (r1.Contains(aa))
            {
                MessageBox.Show("r1");
            }

            if (r2.Contains(aa))
            {
                MessageBox.Show("r2");
            }
        }

你可能感兴趣的:(鼠标位置)