如何避免c#.net中TableLayoutPanel中的闪烁
我使用TableLayoutPanel进行出勤标记。 我在TableLayoutPanel中添加了控件(Panel和Label)并为它们创建了事件。 在某些情况下,我已经清除了所有控件,并继续将相同的控件绑定在TableLayoutPanel的不同位置。 在重新绑定控件时,TableLayoutPanel会在初始化时闪烁并且速度太慢。
暂停布局,直到您添加了所有控件。
TableLayoutPanel panel = new TabelLayoutPanel(); panel.SuspendLayout(); // add controls panel.ResumeLayout();
另请参阅使用Double Buffering。 您必须创建TableLayoutPanel的子类。 在这里查看示例。
这对我来说很有用。 在Windows窗体中删除因TableLayoutPanel和Panel而导致的闪烁
这里链接是什么(复制逐字)
完全删除由于Windows窗体中的TableLayoutPanel和Panel导致的闪烁,如下所示:= – 1.设置Form = true的双缓冲属性。 2.在form.cs中粘贴以下2个函数
#region .. Double Buffered function .. public static void SetDoubleBuffered(System.Windows.Forms.Control c) { if (System.Windows.Forms.SystemInformation.TerminalServerSession) return; System.Reflection.PropertyInfo aProp = typeof(System.Windows.Forms.Control).GetProperty("DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); aProp.SetValue(c, true, null); } #endregion #region .. code for Flucuring .. protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } } #endregion
- 为每个
TableLayoutPannel
,Pannel
,Splitcontainer
,Datagridview
和所有容器控件调用SetDoubleBuffered(“TableLaoutPannel_controlName”)
。感谢RhishikeshLathe发表于16-Feb-14 20:11 pm
使用此面板将属性dBuffer设置为true
public partial class MyTableLayoutPanel : TableLayoutPanel { public MyTableLayoutPanel() { InitializeComponent(); } public MyTableLayoutPanel(IContainer container) { container.Add(this); InitializeComponent(); } /// /// Double buffer /// [Description("Double buffer")] [DefaultValue(true)] public bool dBuffer { get { return this.DoubleBuffered; } set { this.DoubleBuffered = value; } } }
这个代码在另一个问题上提交了它,它使用API调用来设置TableLayoutPanel重绘。
作为上述改进,我有更好的结果:
TableLayoutPanel panel = new TabelLayoutPanel(); panel.SuspendLayout(); panel.StopPaint(); // add controls panel.ResumePaint(); panel.ResumeLayout();