好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

C#双缓冲实现方法(可防止闪屏)

本文实例讲述了C#双缓冲实现方法。分享给大家供大家参考,具体如下:

?

//  该调用是  Windows.Forms  窗体设计器所必需的。

InitializeComponent();

//  TODO:  在  InitComponent  调用后添加任何初始化

this .SetStyle(ControlStyles.AllPaintingInWmPaint, true );

//开启双缓冲

this .SetStyle(ControlStyles.DoubleBuffer, true );

this .SetStyle(ControlStyles.UserPaint, true );

this .SetStyle(ControlStyles.ResizeRedraw, true );

1、在内存中建立一块[虚拟画布]:

?

Bitmap bmp = new Bitmap(600, 600);

2、获取这块内存画布的Graphics引用:

?

Graphics g = Graphics.FromImage(bmp);

3、在这块内存画布上绘图:

?

g.FillEllipse(brush, i * 10, j * 10, 10, 10);

4、将内存画布画到窗口中

?

this .CreateGraphics().DrawImage(bmp, 0, 0);

还有的方式

在构造函数中加如下代码

代码一:

?

SetStyle(ControlStyles.UserPaint, true );

SetStyle(ControlStyles.AllPaintingInWmPaint, true ); // 禁止擦除背景.

SetStyle(ControlStyles.DoubleBuffer, true ); // 双缓冲

代码二:

?

this .SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true );

this .UpdateStyles();

希望本文所述对大家C#程序设计有所帮助。

dy("nrwz");

查看更多关于C#双缓冲实现方法(可防止闪屏)的详细内容...

  阅读:78次