在上位机Windows操作平台( .net 2.0框架集)下实现图形双缓存有很多办法,每种办法在上位机都有很好的效果,但是很不幸,在WinCE4.2操作系统(.net 2.0精简框架集)下这些方法要么不支持,要么效果很差(还是闪烁的厉害)。
在上位机中,一般都有这么几种办法:
1、应用程序中使用双缓冲的最简便的方法是使用.NET Framework为窗体和控件提供的默认双缓冲,通过将DoubleBuffered属性设置为True即可。
2、通过SetStyle修改控件属性。
 public void EnableDoubleBuffering()
{
   // Set the value of the double-buffering style bits to true.
   this.SetStyle(ControlStyles.DoubleBuffer |
      ControlStyles.UserPaint |
      ControlStyles.AllPaintingInWmPaint,
      true);
   this.UpdateStyles();
}
3、比较经典的一种如下:重载OnPaint函数
protected override void OnPaint(PaintEventArgs e)
|'B:lM�k wCg3  {3GEYE�P(i#A$z9U].E#W
a%r4Et:B)o^[-_F3   System.Drawing.Bitmap b = new Bitmap(this.Width,this.Height);//双缓冲技术,先将所有要画的画在该图片中,再调用GS画出该图片.
"i-~/I-F
Nu3   Graphics g = Graphics.FromImage((System.Drawing.Image)b);
~)O~|0Q5OA4Yr3   //在这里画你所需要画的
   //-------------------3GEYE7Exk9V
d%eR:Toj
   e.Graphics.DrawImage((System.Drawing.Image)b,0,0);
RX$ZE'F3   g.Dispose();
   base.OnPaint (e);   
	S	OxLI-`3  }
     前两种办法在WinCE下都不支持,第三种办法是可以使用的,但效果不佳,还是有明显的闪烁现象。经过上网查资料和测试,发现在第三种办法基础上要进行如下处理,效果才非常完美。
   由于我是在Panel上绘的图,所以我派生了一个类EmbedPanel,重载了OnPaintBackground函数,并且置该函数为空。3GEYE&W-}XFjr~+n
    public class EmbedPanel : Panel3GEYE_XPJey%LIg
    {
&vkt%ZXW�xJ_3        protected override void OnPaintBackground(PaintEventArgs paintg)
zb1vSH-^%[%o*P3        {           3GEYE2L.FtJlIZ R
            //不绘制背景3GEYE w,ki
@:Zz
        }3GEYE"iyM+y\'Un
    } 
    private void pb_Paint(object sender, PaintEventArgs e)
BpM\BR|3        {
n	]{,g8v*u$d
D/YEO3            try3GEYE/W
kf,M+N$o$W
            {3GEYEL6f}wr2_2t
                pb_Graphics.FillRectangle(new SolidBrush(BackColor), Rect);  //绘制背景
R'?/R0jx	yh/k6W]3                //--------------------------------------------------------
                ... ... 具体的绘图代码
                //--------------------------------------------------------
:?6@&}	JjcM3                e.Graphics.DrawImage((System.Drawing.Image)pb_Bitmap, 0, 0);3GEYEKpi�sk,T6?w
            }
'RdyC.W Z.]3            catch (Exception err)3GEYEpO�jUm-?6Z
            {
"K
z|-k
Mj$AB~$W\3                ShowInfo(3000, 2, err.Message, "pb_Paint");
-CSXP[3B)g,b3            }3GEYEU,k*|9R7@4_'N cw
        }
   
//注:在WINCE测试时发现,在OnPaint中的写System.Drawing.Bitmap b = new
Bitmap(this.Width,this.Height)代码,程序运行不长时间便会导致WinCE死机。所以我是在类的初始化中执行该代码的。
     这样一来,就很完美的在.net精简框架集下解决了绘图闪烁问题。
 
3GEYE}]m
h qx
/Ym{/zC9f#j3
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1402520