Sae*_*ani 6 c# performance tablelayoutpanel winforms
在我的应用程序中,我真的需要放置很多控件(标签,文本框,domainupdown).所以我继续使用了一些嵌套TableLayoutPanel.现在的问题是,这种形式对大多数事件响应非常缓慢(调整大小,最大化,最小化和......)表格中的控件实际需要花费5秒才能调整大小,重新绘制到新的表单大小.
我现在把手指放在眼睛里!如果这个表格在我的家用电脑上很慢(i7 @ 4GHz和一张好的显卡)它会在旧的P4电脑上运行吗?
我甚至尝试使用下面的代码,但它绝对没有任何东西,如果它不会减慢它的速度!
private void FilterForm_ResizeBegin(object sender, EventArgs e)
{
foreach(TableLayoutPanel tlp in panelFilters.Controls)
{
if(tlp != null)
{
tlp.SuspendLayout();
}
}
}
private void FilterForm_ResizeEnd(object sender, EventArgs e)
{
foreach (TableLayoutPanel tlp in panelFilters.Controls)
{
if (tlp != null)
{
tlp.ResumeLayout();
}
}
}
Run Code Online (Sandbox Code Playgroud)
请告诉我是否有一个技巧可以让tablelayoutpanel更快地工作......或者如果你知道一个更好的方法来放置大约数百个很好地对齐的控件.
NET*_*ET3 21
使用此代码.
public class CoTableLayoutPanel : TableLayoutPanel
{
protected override void OnCreateControl()
{
base.OnCreateControl();
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.CacheText, true);
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= NativeMethods.WS_EX_COMPOSITED;
return cp;
}
}
public void BeginUpdate()
{
NativeMethods.SendMessage(this.Handle, NativeMethods.WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero);
}
public void EndUpdate()
{
NativeMethods.SendMessage(this.Handle, NativeMethods.WM_SETREDRAW, new IntPtr(1), IntPtr.Zero);
Parent.Invalidate(true);
}
}
public static class NativeMethods
{
public static int WM_SETREDRAW = 0x000B; //uint WM_SETREDRAW
public static int WS_EX_COMPOSITED = 0x02000000;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); //UInt32 Msg
}
Run Code Online (Sandbox Code Playgroud)