C#双缓冲实现方法(可防止闪屏)
作者:Microblue 时间:2021-07-07 18:15:33
本文实例讲述了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#,双缓冲
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android Rxjava3 使用场景详解
2023-08-06 08:58:50
![](https://img.aspxhome.com/file/2023/3/84723_0s.jpg)
IDEA中JetBrains Mono字体的正确安装姿势
2022-03-12 12:21:40
![](https://img.aspxhome.com/file/2023/4/87194_0s.jpg)
mybatis-plus的批量新增/批量更新以及问题
2022-10-28 04:44:16
![](https://img.aspxhome.com/file/2023/2/67972_0s.png)
java使用websocket,并且获取HttpSession 源码分析(推荐)
2023-08-04 17:38:05
深入讲解Java Maven配置
2022-07-01 05:09:21
![](https://img.aspxhome.com/file/2023/3/67633_0s.jpg)
IDEA启动tomcat控制台中文乱码问题的解决方法(100%有效)
2021-06-25 10:45:23
![](https://img.aspxhome.com/file/2023/9/62699_0s.jpg)
.NET中的Timer类型用法详解
2022-12-15 18:33:23
![](https://img.aspxhome.com/file/2023/8/83258_0s.png)
Java实现批量向mysql写入数据的方法
2023-11-05 20:51:21
Java PreparedStatement用法详解
2023-08-08 20:20:51
![](https://img.aspxhome.com/file/2023/1/58061_0s.png)
详解IntelliJ IDEA创建spark项目的两种方式
2023-12-05 05:48:21
![](https://img.aspxhome.com/file/2023/0/69660_0s.png)
Mybatis批量插入index out of range错误的解决(较偏的错误)
2022-06-11 01:11:51
![](https://img.aspxhome.com/file/2023/2/84332_0s.png)
深入理解Java设计模式之命令模式
2023-11-24 11:06:31
![](https://img.aspxhome.com/file/2023/4/59684_0s.jpg)
Spingboot JPA CriteriaBuilder 如何获取指定字段
2022-07-20 15:40:22
Unity2D实现游戏回旋镖
2022-07-16 07:13:50
![](https://img.aspxhome.com/file/2023/8/66118_0s.gif)
Spring Cloud Gateway不同频率限流的解决方案(每分钟,每小时,每天)
2023-01-05 13:49:34
Java有哪些操作字符串的类?区别在哪?
2021-06-02 14:50:54
spring mvc中直接注入的HttpServletRequst安全吗
2021-12-29 07:48:16
![](https://img.aspxhome.com/file/2023/6/63506_0s.png)
详解Java 信号量Semaphore
2021-12-22 11:10:36
![](https://img.aspxhome.com/file/2023/7/69927_0s.png)
详解Java中类的加载与其初始化
2023-06-21 04:56:45
![](https://img.aspxhome.com/file/2023/3/65603_0s.png)
关于Java中修饰符的总结(fina除外)
2023-11-22 23:15:57