private List<Line> listLine = new List<Line>(); 
        
        private void Draw_MouseUp(object sender, MouseEventArgs e)
        {
            if (drawingLine == null)
            {
                return;
            }
            drawingLine.EndPoint = e.Location;
            drawingLine = null;
        }        private void Draw_MouseMove(object sender, MouseEventArgs e)
        {
            if (drawingLine != null)
            {
                drawingLine.EndPoint = e.Location;
                this.splitContainer1.Panel2.Refresh();
            }
        }        void drawPanel_Paint(object sender, PaintEventArgs e)
        {
            Bitmap bp = new Bitmap(this.splitContainer1.Panel2.Width, this.splitContainer1.Panel2.Height);
            // 用于缓冲输出的位图对象   
            Graphics g = Graphics.FromImage(bp);
            // 消锯齿(可选项) 
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.SmoothingMode = SmoothingMode.HighQuality; //高质量 
            g.PixelOffsetMode = PixelOffsetMode.HighQuality; //高像素偏移质量
            this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
            Pen p = new Pen(Color.Black);
            foreach (Line line in listLine)
            {
                if (line == drawingLine)
                {
                    // 当前绘制的线条是正在鼠标定位的线条   
                    p.Color = Color.Blue;
                }
                else
                {
                    p.Color = Color.Black;
                }
                g.DrawLine(p, line.StartPoint, line.EndPoint);
            }
            e.Graphics.DrawImage(bp, Point.Empty);
            g.Dispose();
        }        private void Draw_MouseDown(object sender, MouseEventArgs e)
        {
            drawingLine = new Line(e.Location);
            listLine.Add(drawingLine);
        }
//其中drawingLine实例对应的类是Line,Line代码如下:
public class Line
    {
        public Point StartPoint = Point.Empty;
        public Point EndPoint = Point.Empty;        public Line() { }        /// ﹤summary﹥   
        /// 建立线条对象,并设置起点   
        /// ﹤/summary﹥   
        /// ﹤param name="startPoint"﹥此线条的起点﹤/param﹥   
        public Line(Point startPoint)
        {
            StartPoint = startPoint;
            EndPoint = startPoint;
        }
    }
附加一个小问题 http://topic.csdn.net/u/20100915/20/cc30bc01-9a2c-4223-a10a-457e397591db.html两天了都没有人回答,郁闷啊...

解决方案 »

  1.   

    构造函数中写一行
    DoubleBuffered = true;
    试试
      

  2.   

    这个属性窗体中我已经设置了,还是很闪,还上网找了什么双缓存也没用,如果我是在窗体上绘制就不会闪,但是换到一个panel中怎么就那么闪呢?
      

  3.   

    如果窗体上不闪,说明你方法没错。自定义类继承自panel,在构造函数中设置双缓存。
      

  4.   

    建议lz直接继承panel,并重写on_paint方法,在那里面画,效果会好很多
      

  5.   

    借助一下 GraphicsPath 呢? 也许效果会好点吧。