当前位置: 移动技术网 > IT编程>开发语言>c# > C#双缓冲实现方法(可防止闪屏)

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

2019年07月18日  | 移动技术网IT编程  | 我要评论
本文实例讲述了c#双缓冲实现方法。分享给大家供大家参考,具体如下: // 该调用是 windows.forms 窗体设计器所必需的。 initializ

本文实例讲述了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#相关内容感兴趣的读者可查看本站专题:《c#面向对象程序设计入门教程》、《c#常见控件用法教程》及《c#数据结构与算法教程

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

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网