我做了个游戏,老是闪烁,大家都说用双缓冲。
谁有关于双缓冲的例子,最好有注释。
谢谢!

解决方案 »

  1.   

    你是不是用listview这个控件,如果晕这个的话.用doublebufferlistview就可以
    你百度一下doublebufferlistview
    兴许就找到问题的答案喽,good luck
      

  2.   


      class DoubleBufferListView : ListView
        {
            public DoubleBufferListView()
            {
                SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
                UpdateStyles();
            }
        }//
    DoubleBufferListView lv=new DoubleBufferListView();
    lv...
    ...
    才十五分而已,还好拿意思,我每次求贴都是一百分...呵呵
      

  3.   

    15分。HOHO,手上有个之前用过的:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Text;
    using System.Windows.Forms;namespace SquareWave
    {
        public partial class MainForm : Form
        {
            public SW swMain;        private BufferedGraphics backBuffer;            //双缓冲的缓冲区。        private BufferedGraphics backgroundBuffer;      //背景缓冲区:坐标轴,刻度,参考线
            public MainForm(SW sw)
            {
                InitializeComponent();            this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
                       ControlStyles.ResizeRedraw |
                       ControlStyles.AllPaintingInWmPaint, true);            if (sw == null)
                {
                    sw = new SW(changeSWPos);
                }
                else
                {
                    sw.SetChangeHandle(changeSWPos);
                }            swMain = sw;
                swMain.DoSWPChanged();
            }
            private void changeSWPos(int Left, int Top, int Width, int Height)
            {
                panRight.Refresh();
                nudT.Value = swMain.TimeStart;
                nudR.Value = swMain.RangeValue;
                nudP.Value = swMain.PersistTime;
                txtSWPos.Text = "[" + Left.ToString() + "," + Top.ToString() + "]  [" + Width.ToString() + "," + Height.ToString() + "]";
            }
            public const int opX = 30;
            public const int opY = 310;        public const int dX = 50;
            public const int dY = 50;        public const int cX = 8;
            public const int cY = 6;        public int HFramePos;
            public int VFramePos;
            #region 绘图方法        private void panRight_Paint(object sender, PaintEventArgs e)
            {
                //手工绘制坐标轴       
                if (backgroundBuffer == null)
                {
                    Rectangle rect = e.ClipRectangle;
                    BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
                    backgroundBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);
                    backgroundBuffer.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                    backgroundBuffer.Graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;                Graphics gBG = backgroundBuffer.Graphics;
                    gBG.Clear(Color.White);
                    drawAXIS(gBG);                //绘制坐标轴
                    drawTEXTRefLine(gBG);         //绘制坐标轴文字
                }            if (backBuffer == null)
                {
                    Rectangle rect = e.ClipRectangle;
                    BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
                    backBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);
                    backBuffer.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                    backBuffer.Graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
                }
                //用背景缓冲区渲染双缓冲
                backgroundBuffer.Render(backBuffer.Graphics);            Graphics g = backBuffer.Graphics;            drawSW(g);                  //绘制方波
                drawFrame(g);               //绘制拖放时的边框
                backBuffer.Render(e.Graphics);      //双缓冲防闪烁(暂时未达到效果)        }
        
        }
    }
      

  4.   

      class DoubleBufferListView : ListView
        {
            public DoubleBufferListView()
            {
                SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
                UpdateStyles();
            }
        }
    把这个ListView改成其它的不可用吗?