C#中双缓存技术

来源:互联网 发布:cad手机画图软件 编辑:程序博客网 时间:2024/05/15 06:59
 

 protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Rectangle rect = e.ClipRectangle;
            BufferedGraphicsContext curentContext = BufferedGraphicsManager.Current;
            BufferedGraphics myBuffer = curentContext.Allocate(e.Graphics, e.ClipRectangle);
            Graphics g = myBuffer.Graphics;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighSpeed;
            g.Clear(this.BackColor);

            // To Do 繪一些你需要的信息到 g
            ......
            //

            myBuffer.Render(e.Graphics);
            g.Dispose();
            myBuffer.Dispose();                       
        }