C# winForm 窗体闪烁问题

如果你在Form中绘图的话,不论是不是采用的双缓存,都会看到图片在更新的时候都会不断地闪烁,解决方法就是在这个窗体的构造函数中增加以下三行代码:

请在构造函数里面底下加上如下几行:
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲

参数说明:

UserPaint 
如果为 true,控件将自行绘制,而不是通过操作系统来绘制。此样式仅适用于派生自 Control 的类。

AllPaintingInWmPaint 
如果为 true,控件将忽略 WM_ERASEBKGND 窗口消息以减少闪烁。仅当 UserPaint 位设置为 true 时,才应当应用该样式。

DoubleBuffer 
如果为 true,则绘制在缓冲区中进行,完成后将结果输出到屏幕上。双重缓冲区可防止由控件重绘引起的闪烁。要完全启用双重缓冲,还必须将 UserPaint 和 AllPaintingInWmPaint 样式位设置为 true。

另外有个简便的复制方法:

SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);

this.UpdateStyles();

时间: 2025-01-15 00:29:56

C# winForm 窗体闪烁问题的相关文章

c# winform窗体闪烁解决方法

在主窗体中任意位置加上下面的代码即可 protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } } c# winform窗体闪烁解决方法

解决winform窗体闪烁问题

如果你在Form中绘图的话,不论是不是采用的双缓存,都会看到图片在更新的时候都会不断地闪烁,解决方法就是在这个窗体的构造函数中增加以下三行代码: 请在构造函数里面底下加上如下几行: SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景. SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲 参数说明

WinForm 窗体闪烁 & 任务栏提示

准备: 1 [DllImport("user32.dll")] 2 static extern bool FlashWindowEx(ref FLASHWINFO pwfi); 3 4 [DllImport("user32.dll")] 5 static extern bool FlashWindow(IntPtr handle, bool invert); 6 7 [StructLayout(LayoutKind.Sequential)] 8 public str

winform窗体中查找控件

private RichTextBox FindControl()        { RichTextBox ret = null;            try            {                Control[] controls = Application.OpenForms["MainForm"].Controls.Find("txtContent", false);                if (controls != nul

c#Winform窗体 自动生成EXCEL并可以插入数据

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data; using System.Windows.Forms; using System.Data.OleDb;using System.IO;using System.Drawing;using System.Linq;using System.Text; namespace EPAS.f06PreData//自己命名

C#使用事件方式Winform窗体之间传值

[摘自:http://www.cnblogs.com/codeToUp/p/5371062.html] 工程的源代码地址:https://github.com/yes-or-no/WinFormTransValueDemoByDelOrEvent.git C#winform窗体间传值,三种方法示例,注释详细.使用方法:使用vs2013打开编译运行即可: 工程中总共介绍了三种方法:###方法1:通过保存对象的引用调用其方法实现对子窗体的控制:###方法2:通过委托,在子窗体显示之前,为委托赋值,关

WPF加载Winform窗体时 报错:子控件不能为顶级窗体

一.wpf项目中引用WindowsFormsIntegration和System.Windows.Forms 二.Form1.Designer.cs 的 partial class Form1 设置为:public partial class Form1 三.代码如下: XXXX.Form1 Zhuwindow = new XXXX.Form1(); Zhuwindow.TopLevel = false; Zhuwindow.FormBorderStyle = System.Windows.Fo

.NET vs2010中使用IrisSkin2.dll轻松实现winForm窗体换肤功能

.NET vs2010中使用IrisSkin2.dll轻松实现winForm窗体换肤功能 转载▼ 大家好,从事c-s开发的C#程序员经常为winForm的界面设计苦恼,笔者曾经也深受“美工神话”的危害,如今提到美工,界面布局设计就开始蛋疼…. 所幸的是,笔者无意间接触到了一些比较可爱的第三方控件,可以为我们程序员省掉很多美工上面的麻烦…在陆续的博客中我会为大家介绍,今天我们的主题是:IrisSkin2.dll IrisSkin2.dll是一款很不错的免费皮肤控件,利用它可以轻松的实现winFor

小例子(二)、winform窗体间的关系

写一个关于winform窗体间的关系 1.登陆,思路:登陆后隐藏登陆窗体,关闭Form2时结束整个应用程序. 1 //登陆窗体 2 private void button2_Click(object sender, EventArgs e) 3 { 4 Form2 fr = new Form2(); 5 this.Visible = false;//隐藏窗体 6 fr.Show(); 7 } 1 //注册一个关闭时结束程序的事件,FormClosing 2 private void Form2_