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);
}