各位大大  小弟初学 在写一个画板程序 又遇到了一个问题  在画椭圆和长方形的时候 要实现动态拉动的那个效果  我想的办法是记录下位置鼠标每移动一下就画个新的位置然后把上一个用白画笔再画一次 但是这样的话就可能擦掉之前画的图形代码如下private void panelDraw_MouseMove(object sender, MouseEventArgs e)
        {
            if (isPainting == 1)
            {
                Graphics gD = panelDraw.CreateGraphics();
                Pen bP = new Pen(Color.Black);
                Pen wP = new Pen(Color.White);
               
                switch(selectedTool)
                {
                    case tool.pencil:                        Point p = e.Location;
                        lP.Add(p);
                        Point[] points = lP.ToArray();
                        GraphicsPath gp = new GraphicsPath();
                        gp.AddLines(points);
                        gD.DrawPath(bP, gp);
                        break;
                    case tool.ellipse:
                        Point lastPointE = (Point)lP.Last();
                      float  widthOf = Math.Abs(lastPointE.X - startPoint.X);
                      float  heightOf = Math.Abs(lastPointE.Y - startPoint.Y);
                      gD.DrawEllipse(wP, compare(startPoint.X,lastPointE.X), compare(startPoint.Y,lastPointE.Y), widthOf, heightOf);
                      lP.Add(e.Location);
                      float widthOfNew = Math.Abs(e.X - startPoint.X);
                      float heightOfNew = Math.Abs(e.Y - startPoint.Y);
                      gD.DrawEllipse(bP, compare(startPoint.X,e.X), compare(startPoint.Y,e.Y), widthOfNew, heightOfNew);
                      gD.Dispose();
                      break;
                    case tool.rectangle:
                      Point lastPointR = (Point)lP.Last();
                      float widthOfR = Math.Abs(lastPointR.X - startPoint.X);
                      float heightOfR = Math.Abs(lastPointR.Y - startPoint.Y);
                      gD.DrawRectangle(wP, compare(startPoint.X, lastPointR.X), compare(startPoint.Y, lastPointR.Y), widthOfR, heightOfR);
                      lP.Add(e.Location);
                      float widthOfNewR = Math.Abs(e.X - startPoint.X);
                      float heightOfNewR = Math.Abs(e.Y - startPoint.Y);
                      gD.DrawRectangle(bP, compare(startPoint.X, e.X), compare(startPoint.Y, e.Y), widthOfNewR, heightOfNewR);
                      gD.Dispose();
                      break;
                    case tool.eraser:
                      gD.FillRectangle(Brushes.White, e.X - 8, e.Y - 8, 16, 16);
                      gD.Dispose();
                    
                      break;                       
                       
                }
               
            }
             
        }