Winform FlowLayoutPanel 性能闪烁以及渲染效率问题优化
winform flowlayoutpanel 性能优化 以及 闪烁问题的解决办法
try
{
UserControl1[] ucList = new UserControl1[100];//定义一个控件数组 用于存放多个控件
flowLayoutPanel1.SuspendLayout();//添加控件内容前临时挂起布局逻辑 等添加完成后统一渲染
for (int i = 0; i <ucList.Length; i++)
{
UserControl1 c = new UserControl1();//新建一个用户控件
c.Text = i.ToString();
c.BackColor = Color.OrangeRed;
ucList[i] = c;//将用户控件放入控件数组集合
}
flowLayoutPanel1.Controls.AddRange(ucList);//一次性将控件数组添加入 flowLayoutPanel1
}
finally
{
flowLayoutPanel1.ResumeLayout();//恢复正常布局 及渲染
}
///启用双缓冲 解决列表滑动闪烁问题
flowLayoutPanel1.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.NonPublic) .SetValue(flowLayoutPanel1, true, null);