winform 双缓冲技术解决闪硕

来源:互联网 发布:高铁隧道输电网络照片 编辑:程序博客网 时间:2024/06/05 10:41

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

以双缓冲技术解决。

            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,则还应当将 UserPaint 和AllPaintingInWmPaint 设置为 true。 OptimizedDoubleBuffer如果为 true,则该控件首先在缓冲区中绘制,而不是直接绘制到屏幕上,这样可以减少闪烁。如果将此属性设置为 true,则还应当将 AllPaintingInWmPaint 设置为 true。 UseTextForAccessibility指定该控件的 Text 属性的值,如果已设置,则可确定该控件的默认 Active Accessibility 名称和快捷键。
原创粉丝点击