自定义控件闪烁问题
今天看UI 设计 无意中 想起 之前 自定义控件闪烁的情况 于是上网搜索
http://www.docin.com/p-269578584.html
C#双缓存解决自定义控件闪屏问题 在C# WinForm编程中,我们经常会遇见某个自定义控件闪烁得很 厉害的情况,即便将窗体DoubleBuffered属性设置为True也无济于事。 终于在万能的百度知道里问道了方法:
base.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
base.UpdateStyles();
于是在窗体初始化时加入上 述语句、F5、移动自定义控件, 闪依旧。 看来,加的地方不对。进入 自定义控件初始化阶段增加语 句、F5、移动自定义控件,^_^成功啦。 但是,一般地我习惯自定义 很多控件,所以就来一个一次封 装重复使用:
1 namespace haha.Controls { 2 3 public class DoubleBufferdPanel : System.Windows.Forms.Panel { public DoubleBufferdPanel() : base() { base.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); 4 5 base.UpdateStyles(); } } 6 7 public class DoubleBufferdPictureBox : System.Windows.Forms.PictureBox 8 9 { 10 11 public DoubleBufferdPictureBox() : base() 12 13 { 14 15 base.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); 16 17 base.UpdateStyles(); 18 19 } 20 21 } 22 23 public class DoubleBufferdControl: System.Windows.Forms.UserControl 24 25 { 26 27 public DoubleBufferdControl() : base() 28 29 { base.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); 30 31 base.UpdateStyles(); 32 33 } 34 35 } 36 37 }
然后再搜索 下面这个 说的比较详细
如果你觉得写的不错,欢迎转载和点赞。 转载时请保留作者署名jilodream/王若伊_恩赐解脱(博客链接:http://www.cnblogs.com/jilodream/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)