22

I would like to set my form to be exactly 300*300 excluding heading and borders.

If I use Size property, it does include these values.

Is there any way how to do it?

WonderWorker
  • 8,539
  • 4
  • 63
  • 74
Mocco
  • 1,183
  • 2
  • 12
  • 25

3 Answers3

32

You have two options, as follows:

  • To remove heading and borders from a Form, disable the Form's FormBorderStyle property.

  • Set the interior of the form with the ClientSize property, as follows:

    this.ClientSize = new Size(300, 300);
    
WonderWorker
  • 8,539
  • 4
  • 63
  • 74
Yetti
  • 1,710
  • 1
  • 14
  • 28
  • So it is not possible set the clientSize in the designer, right? I just need window that is 300x300 EXCLUDING borders and header – Mocco Feb 24 '11 at 15:43
  • Correct, there doesn't seem to be any way to set this in designer. However, you can always just set this in the Load or Paint event and the user will never know the difference. – Yetti Feb 24 '11 at 15:46
  • 1
    To add on to my last comment, it is better to do this on the Load event because it happens once on Load, whereas Paint happens many times throughout execution, so there is really no point in resetting the client size every time the form is painted. – Yetti Feb 24 '11 at 15:58
9

Why not just factor in the size of the border and the title bar?

int BorderWidth = (this.Width – this.ClientSize.Width) /2;
int TitlebarHeight = this.Height – this.ClientSize.Height – 2 * BorderWidth;

I found the formulas here.

dandan78
  • 13,328
  • 13
  • 64
  • 78
  • this.ClientSize gives the size without borders. This might not be what OP asks for, but it's certainly what I needed. – WSBT Nov 15 '13 at 17:34
6

There is workaround to set proper Size by designer tool: 1. Set FormBorderSize to "None". 2. Set prefered Size (e.g. "300; 300"). 3. Set FormBorderSize to prefered border (additional needed space will be added to Size property automaticly).

Marek Kijo
  • 173
  • 1
  • 9