自定义控件闪烁问题
今天看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/