自定义控件闪烁问题

今天看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 }
复制代码

 

 

然后再搜索 下面这个  说的比较详细

http://wenku.baidu.com/view/f811d6a2f524ccbff121840b.html

posted @   王若伊_恩赐解脱  阅读(898)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)

点击右上角即可分享
微信分享提示