谢了,有没有例子我看一下,对这个一无所知,学winform不久,请高手指点一下!

解决方案 »

  1.   

    pannel控件上有鼠标的按下事件panel1_MouseDown和panel1_MouseUp利用这两个事件。来计算。在鼠标按下的时候,记住那个点( intX = e.X;
    intY = e.Y;)在鼠标弹起的时候,记住这个点。利用这两个点计算。画好以后。不刷新的话。是不显示的。
      

  2.   

    You might use ControlPaint.DrawReversibleFrame:
        public partial class Form1 : Form
        {
            Point startPoint;
            Rectangle lastRect;
            bool isDragging;        public Form1()
            {
                InitializeComponent();
            }        protected override void OnMouseDown(MouseEventArgs e)
            {
                startPoint = this.PointToScreen(e.Location);
                lastRect = new Rectangle(0, 0, 0, 0);
                isDragging = true;
            }
            protected override void OnMouseMove(MouseEventArgs e)
            {
                if (isDragging )
                {
                    Point current = this.PointToScreen(e.Location);
                    int width = current.X - startPoint.X;
                    int height = current.Y - startPoint.Y;                ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed);
                    lastRect = new Rectangle(startPoint, new Size(width, height));
                    ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed);
                }
            }
            protected override void OnMouseUp(MouseEventArgs e)
            {
                if (isDragging)
                {
                    isDragging = false;
                    ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed);                MessageBox.Show("the rect is " + lastRect);
                }
            }
        }
    From: GDI +画橡皮线的问题
      

  3.   

    blog.csdn.net/dunao
    看看这个吧!应该就是你想要的
      

  4.   

    要在OnMouseDown和OnMouseMove事件里面用e.X,和e.Y坐标来取得长和宽
    然后记录下来作为你矩形的长和宽