CoTableLayoutPanel.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace SIMDP
  12. {
  13. //public partial class CoTableLayoutPanel : Control
  14. //{
  15. // public CoTableLayoutPanel()
  16. // {
  17. // InitializeComponent();
  18. // }
  19. // protected override void OnPaint(PaintEventArgs pe)
  20. // {
  21. // base.OnPaint(pe);
  22. // }
  23. //}
  24. public partial class CoTableLayoutPanel : TableLayoutPanel
  25. {
  26. protected override void OnCreateControl()
  27. {
  28. base.OnCreateControl();
  29. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.CacheText, true);
  30. // this.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
  31. }
  32. protected override CreateParams CreateParams
  33. {
  34. get
  35. {
  36. CreateParams cp = base.CreateParams;
  37. cp.ExStyle |= NativeMethods.WS_EX_COMPOSITED;
  38. return cp;
  39. }
  40. }
  41. public void BeginUpdate()
  42. {
  43. NativeMethods.SendMessage(this.Handle, NativeMethods.WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero);
  44. }
  45. public void EndUpdate()
  46. {
  47. NativeMethods.SendMessage(this.Handle, NativeMethods.WM_SETREDRAW, new IntPtr(1), IntPtr.Zero);
  48. Parent.Invalidate(true);
  49. }
  50. }
  51. public static class NativeMethods
  52. {
  53. public static int WM_SETREDRAW = 0x000B; //uint WM_SETREDRAW
  54. public static int WS_EX_COMPOSITED = 0x02000000;
  55. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  56. public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); //UInt32 Msg
  57. }
  58. }