title: Custom Resize Handle in Border-less Form C#
body: <p>I'm attempting to make border-less forms that pop out of a tool bar. I want the user to be able to grab at the bottom-right corner (a "resize handle") and be able to resize the form, but not be able to resize or reposition the form in any other way.</p>
  
  <p>I've heard that I can intercept the <code>WM_NCHITTEST</code> message sent to the form and set its result to <code>HTBOTTOMRIGHT</code> which will let the operating system handle the re-sizing of the form, just as if it had a sizable frame. The idea I had was to detect if the mouse pointer had entered a box I defined in the corner and if it did then return the <code>HTBOTTOMRIGHT</code> result.</p>
  
  <p><img src="https://i.stack.imgur.com/XcZLE.png" alt="Graphic illustrating the resize handle"></p>
  
  <p>This doesn't quite work as I expected it to. I'm able to intercept the message, but it seems the message is only sent when the user positions the mouse cursor on the 1px thick border of the form. That means it works how I want to, if you very precisely position your cursor on the bottom-right edges.</p>
  
  <p>Here is my <code>WndProc</code> override:</p>
  
  <pre><code>protected override void WndProc(ref Message m)
  {
      const UInt32 WM_NCHITTEST = 0x0084;
      const UInt32 HTBOTTOMRIGHT = 17;
      const int RESIZE_HANDLE_SIZE = 40;
      bool handled = false;
      if (m.Msg == WM_NCHITTEST)
      {
          Size formSize = this.Size;
          Point screenPoint = new Point(m.LParam.ToInt32());
          Point clientPoint = this.PointToClient(screenPoint);
          Rectangle hitBox = new Rectangle(formSize.Width - RESIZE_HANDLE_SIZE, formSize.Height - RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE);
          if (hitBox.Contains(clientPoint))
          {
              m.Result = (IntPtr)HTBOTTOMRIGHT;
              handled = true;
          }
      }
  
      if (!handled)
          base.WndProc(ref m);
  }
  </code></pre>
  
  <p>Am I doing something wrong or is there a better way to do what I'm trying to do?</p>
  
  <p>Much thanks.</p>