加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

C# 控件双缓冲控制

(2011-03-04 11:47:21)
标签:

c

control

双缓冲

杂谈

分类: Programm

项目中,控件在大小变化时会有闪烁现象。

以双缓冲技术解决。

            this.SetStyle(ControlStyles.OptimizedDoubleBuffer
                       | ControlStyles.ResizeRedraw
                       | ControlStyles.Selectable
                       | ControlStyles.AllPaintingInWmPaint
                       | ControlStyles.UserPaint
                       | ControlStyles.SupportsTransparentBackColor,
                     true);

 

或:

            this.SetStyle(ControlStyles.UserPaint, true);//自绘
            this.SetStyle(ControlStyles.DoubleBuffer, true);// 双缓冲
            this.SetStyle(ControlStyles.ResizeRedraw, true);//调整大小时重绘
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);// 双缓冲
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);   //透明效果
       

引:

 

成员名称           说明

 

 

UserPaint 如果为 true,控件将自行绘制,而不是通过操作系统来绘制。如果为 false,将不会引发 Paint 事件。此样式仅适用于派生自 Control 的类。
Opaque 如果为 true,则控件被绘制为不透明的,不绘制背景。
ResizeRedraw 如果为 true,则在调整控件大小时重绘控件。
FixedWidth 如果为 true,则自动缩放时,控件具有固定宽度。例如,如果布局操作试图重新缩放控件以适应新的 Font,则控件的 Width 将保持不变。
FixedHeight 如果为 true,则自动缩放时,控件具有固定高度。例如,如果布局操作试图重新缩放控件以适应新的 Font,则控件的 Height 将保持不变。
StandardClick 如果为 true,则控件将实现标准 Click 行为。
Selectable 如果为 true,则控件可以接收焦点。
UserMouse 如果为 true,则控件完成自己的鼠标处理,因而鼠标事件不由操作系统处理。
SupportsTransparentBackColor 如果为 true,控件接受 alpha 组件小于 255 的 BackColor 以模拟透明。仅在 UserPaint 位设置为 true 并且父控件派生自 Control 时才模拟透明。
StandardDoubleClick 如果为 true,则控件将实现标准 DoubleClick 行为。如果 StandardClick 位未设置为 true,则忽略此样式。
AllPaintingInWmPaint 如果为 true,控件将忽略 WM_ERASEBKGND 窗口消息以减少闪烁。仅当 UserPaint 位设置为 true 时,才应当应用该样式。
CacheText 如果为 true,控件保留文本的副本,而不是在每次需要时从 Handle 获取文本副本。此样式默认为 false。此行为提高了性能,但使保持文本同步变得困难。
EnableNotifyMessage 如果为 true,则为发送到控件的 WndProc 的每条消息调用 OnNotifyMessage 方法。此样式默认为 falseEnableNotifyMessage 在部分可信的情况下不工作。
DoubleBuffer 如果为 true,则绘制在缓冲区中进行,完成后将结果输出到屏幕上。双重缓冲区可防止由控件重绘引起的闪烁。如果将 DoubleBuffer 设置为 true,则还应当将 UserPaintAllPaintingInWmPaint 设置为 true
OptimizedDoubleBuffer 如果为 true,则该控件首先在缓冲区中绘制,而不是直接绘制到屏幕上,这样可以减少闪烁。如果将此属性设置为 true,则还应当将 AllPaintingInWmPaint 设置为 true
UseTextForAccessibility 指定该控件的 Text 属性的值,如果已设置,则可确定该控件的默认 Active Accessibility 名称和快捷键。

 

 

Reference: MSDN

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有