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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM