title: Can't resize a borderless winform from top because of a docked panel
body: <p>I made a borderless Windows Form, added drop shadow, the ability to drag, and the ability to resize it from any angle, here's what I did, it's a little messy:</p>
  
  <pre><code>using System.Runtime.InteropServices;
  
  public class MAIN
  {
      [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
      private static extern IntPtr CreateRoundRectRgn
      (
          int nLeftRect, // x-coordinate of upper-left corner
          int nTopRect, // y-coordinate of upper-left corner
          int nRightRect, // x-coordinate of lower-right corner
          int nBottomRect, // y-coordinate of lower-right corner
          int nWidthEllipse, // height of ellipse
          int nHeightEllipse // width of ellipse
      );
      [DllImport("dwmapi.dll")]
      public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
      [DllImport("dwmapi.dll")]
      public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
      [DllImport("dwmapi.dll")]
      public static extern int DwmIsCompositionEnabled(ref int pfEnabled);
      private bool m_aeroEnabled;                     // variables for box shadow
      private const int CS_DROPSHADOW = 0x00020000;
      private const int WM_NCPAINT = 0x0085;
      private const int WM_ACTIVATEAPP = 0x001C;
      public struct MARGINS                           // struct for box shadow
      {
          public int leftWidth;
          public int rightWidth;
          public int topHeight;
          public int bottomHeight;
      }
      private const int WM_NCHITTEST = 0x84;          // variables for dragging the form
      private const int HTCLIENT = 0x1;
      private const int HTCAPTION = 0x2;
      protected override CreateParams CreateParams
      {
          get
          {
              m_aeroEnabled = CheckAeroEnabled();
  
              CreateParams cp = base.CreateParams;
              if (!m_aeroEnabled)
                  cp.ClassStyle |= CS_DROPSHADOW;
  
              return cp;
          }
      }
      private bool CheckAeroEnabled()
      {
          if (Environment.OSVersion.Version.Major &gt;= 6)
          {
              int enabled = 0;
              DwmIsCompositionEnabled(ref enabled);
              return (enabled == 1) ? true : false;
          }
          return false;
      }
      protected override void WndProc(ref Message m)
      {
          const int wmNcHitTest = 0x84;
          const int htLeft = 10;
          const int htRight = 11;
          const int htTop = 12;
          const int htTopLeft = 13;
          const int htTopRight = 14;
          const int htBottom = 15;
          const int htBottomLeft = 16;
          const int htBottomRight = 17;
          bool handled = false;
          switch (m.Msg)
          {
              case WM_NCPAINT:                        // box shadow
                  if (m_aeroEnabled)
                  {
                      var v = 2;
                      DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
                      MARGINS margins = new MARGINS()
                      {
                          bottomHeight = 1,
                          leftWidth = 1,
                          rightWidth = 1,
                          topHeight = 1
                      };
                      DwmExtendFrameIntoClientArea(this.Handle, ref margins);
  
                  }
                  break;
              default:
                  break;
          }
          if (m.Msg == wmNcHitTest)
          {
              int x = (int)(m.LParam.ToInt64() &amp; 0xFFFF);
              int y = (int)((m.LParam.ToInt64() &amp; 0xFFFF0000) &gt;&gt; 16);
              Point pt = PointToClient(new Point(x, y));
              Size clientSize = ClientSize;
              ///allow resize on the lower right corner
              if (pt.X &gt;= clientSize.Width - 16 &amp;&amp; pt.Y &gt;= clientSize.Height - 16 &amp;&amp; clientSize.Height &gt;= 16)
              {
                  m.Result = (IntPtr)(IsMirrored ? htBottomLeft : htBottomRight);
                  return;
              }
              ///allow resize on the lower left corner
              if (pt.X &lt;= 16 &amp;&amp; pt.Y &gt;= clientSize.Height - 16 &amp;&amp; clientSize.Height &gt;= 16)
              {
                  m.Result = (IntPtr)(IsMirrored ? htBottomRight : htBottomLeft);
                  return;
              }
              ///allow resize on the upper right corner
              if (pt.X &lt;= 16 &amp;&amp; pt.Y &lt;= 16 &amp;&amp; clientSize.Height &gt;= 16)
              {
                  m.Result = (IntPtr)(IsMirrored ? htTopRight : htTopLeft);
                  return;
              }
              ///allow resize on the upper left corner
              if (pt.X &gt;= clientSize.Width - 16 &amp;&amp; pt.Y &lt;= 16 &amp;&amp; clientSize.Height &gt;= 16)
              {
                  m.Result = (IntPtr)(IsMirrored ? htTopLeft : htTopRight);
                  return;
              }
              ///allow resize on the top border
              if (pt.Y &lt;= 16 &amp;&amp; clientSize.Height &gt;= 16)
              {
                  m.Result = (IntPtr)(htTop);
                  return;
              }
              ///allow resize on the bottom border
              if (pt.Y &gt;= clientSize.Height - 16 &amp;&amp; clientSize.Height &gt;= 16)
              {
                  m.Result = (IntPtr)(htBottom);
                  return;
              }
              ///allow resize on the left border
              if (pt.X &lt;= 16 &amp;&amp; clientSize.Height &gt;= 16)
              {
                  m.Result = (IntPtr)(htLeft);
                  return;
              }
              ///allow resize on the right border
              if (pt.X &gt;= clientSize.Width - 16 &amp;&amp; clientSize.Height &gt;= 16)
              {
                  m.Result = (IntPtr)(htRight);
                  return;
              }
          }
          if (!handled)
              base.WndProc(ref m);
      }
      public MAIN()
      {
          InitializeComponent();
          m_aeroEnabled = false;
      }
      private Point mMousePos;
      private Point mFormPos;
      private bool mDragging;
      private void Header_MouseDown(object sender, MouseEventArgs e)
      {
          mDragging = true;
          mMousePos = Header.PointToScreen(e.Location);
          mFormPos = Location; 
      } 
      private void Header_MouseUp(object sender, MouseEventArgs e)
      {
          mDragging = false;     
      }
      private void Header_MouseMove(object sender, MouseEventArgs e)
      {
          if (!mDragging) return;
          Point pos = Header.PointToScreen(e.Location);
          Left = mFormPos.X + pos.X - mMousePos.X;
          Top = mFormPos.Y + pos.Y - mMousePos.Y;
      }
  }
  </code></pre>
  
  <p><code>MAIN</code> is the form's name, while <code>Header</code> is the name of my panel, the problem I have is with trying to resize from top, because the panel is docked, also I want to put this code in a class and call it whenever I create a new form. Any help is massively appreciated.</p>