Skip to content

Instantly share code, notes, and snippets.

@devlights
Last active June 8, 2020 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devlights/827b357db3b1763d668a19bdbd878071 to your computer and use it in GitHub Desktop.
Save devlights/827b357db3b1763d668a19bdbd878071 to your computer and use it in GitHub Desktop.
class TableLayoutPanelEx : 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(Handle, NativeMethods.WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero);
}
public void EndUpdate()
{
NativeMethods.SendMessage(Handle, NativeMethods.WM_SETREDRAW, new IntPtr(1), IntPtr.Zero);
Parent.Invalidate(true);
}
}
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment