WEB开发网
开发学院软件开发C语言 鼠标来画矩形 阅读

鼠标来画矩形

 2012-05-29 11:06:59 来源:WEB开发网   
核心提示:namespace MyWay{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } i
namespace MyWay
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
       
            
        }

        int RectangleStartX1 = 0;
        int RectangleStartY1 = 0;
        int RectangleEndX2=0;
        int RectangleEndY2=0;
        int wide = 0;
        int height = 0;
        
       

        public void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                RectangleStartX1 = e.X;
                RectangleStartY1 = e.Y;
              
            }
        }

      

        public void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
          
                RectangleEndX2 = e.X;
                RectangleEndY2 = e.Y;
            
            wide = e.X - RectangleStartX1;
            height = e.Y - RectangleStartY1;
            
           
        }

        public void  pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen pen = new Pen(Color.Green, 2);
            e.Graphics.DrawRectangle(pen, RectangleStartX1, RectangleStartY1, wide, height);
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            pictureBox1.Refresh();
        }

       

      
        }
}

Tags:鼠标 矩形

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接