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?
Select the form, then find the Properties pane in Visual Studio. Scroll down to size and expand it. You can set the Width and Height manually.
Creating our Resizable FormOpen Visual Studio and select "Windows Forms Application" from the list of available templates and name it "DynamicallyPositioningControls". Rename your form to "frmDynamicResizing" by setting its Name property and sets its Text property to "Dynamic Resizing Form".
The client area of a form is the area within a form where controls can be placed. You can use this property to get the proper dimensions when performing graphics operations or when sizing and positioning controls on the form.
Remarks. This property enables you to set the starting position of the form when it is displayed at run time. The form's position can be specified manually by setting the Location property or use the default location specified by Windows.
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With