WinFom解决最小化最大化后重绘窗口造成闪烁的问题
网上两种方案(可协同)
1 设置双缓冲:
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
2 捕获最大化最小化事件,临时挂起布局逻辑
const int WM_SYSCOMMAND = 0x112;
const int SC_CLOSE = 0xF060;
const int SC_MINIMIZE = 0xF020;
const int SC_MAXIMIZE = 0xF030;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_SYSCOMMAND)
{
if (m.WParam.ToInt32() == SC_MINIMIZE) //是否点击最小化
{
this.SuspendLayout();
this.WindowState = FormWindowState.Minimized;
this.ResumeLayout(false);
}
if (m.WParam.ToInt32() == SC_MAXIMIZE)
{
this.SuspendLayout();
this.WindowState = FormWindowState.Maximized;
this.ResumeLayout(false);
}
if (m.WParam.ToInt32() == SC_CLOSE)
{ //.....................
}
}
base.WndProc(ref m);
}
WinForm闪烁修复技巧
本文介绍了解决WinForm应用程序在窗口最小化或最大化时出现闪烁问题的两种有效方法。一是通过设置双缓冲来减少重绘时的闪烁;二是捕获最小化和最大化事件,临时挂起布局逻辑,避免在状态改变时进行不必要的重绘。
657

被折叠的 条评论
为什么被折叠?



