Rectangle rect = e.ClipRectangle;            BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
            BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);
            Graphics g = myBuffer.Graphics;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighSpeed;
            g.Clear(this.BackColor);
            
            foreach (IShape drawobject in doc.drawObjectList)
            {
                if (rect.IntersectsWith(drawobject.Rect))
                {
                    drawobject.Draw(g);
                    if (drawobject.TrackerState == config.Module.Core.TrackerState.Selected
                        && this.CurrentOperator == Enum.Operator.Transfrom)//仅当编辑节点操作时显示图元热点
                    {
                        drawobject.DrawTracker(g);
                    }
                }
            }            myBuffer.Render(e.Graphics);
            g.Dispose();
            myBuffer.Dispose();//释放资源谁能告诉我在哪个foreach中的doc是什么变量,怎么来的 ,,,求解释双缓冲c#

解决方案 »

  1.   

    要是猜得不错的话,这些代码可能是需要画一个图形之类的,doc应该在上文有定义,楼主这只是其中一部分代码
      

  2.   

    双缓冲,加下面的代码
    this.SetStyle(ControlStyles.DoubleBuffer, true);
    this.SetStyle(ControlStyles.UserPaint, true);
    this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
      

  3.   

    this.SetStyle(ControlStyles.DoubleBuffer, true);
    this.SetStyle(ControlStyles.UserPaint, true);
    this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
    方式可以,用过后基本不闪烁了,原来很闪