SoFunction
Updated on 2025-03-07

c# method to change the size of the form by dragging and double-clicking the title bar

I recently wrote a Windows Form program and found an annoying problem.

The Maximization button is disabled and maximized when the form is initialized. This hopes that the form will be maximized. But drag and double-click the title bar, the form will shrink. I'm so annoyed +_+.

Finally, a solution was found.

//Don't change the form size by dragging and double-clicking the title bar.  public const int WM_NCLBUTTONDBLCLK = 0xA3;
  const int WM_NCLBUTTONDOWN = 0x00A1;
  const int HTCAPTION = 2;
  protected override void WndProc(ref Message m)
  {
    if ( == WM_NCLBUTTONDOWN && .ToInt32() == HTCAPTION)
      return;
    if ( == WM_NCLBUTTONDBLCLK)
      return;

      (ref m)·}
    }
   }

The above C# method for not changing the size of the form by dragging and double-clicking the title bar is all the content I share with you. I hope you can give you a reference and I hope you can support me more.