Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the size of the visible area of a form, minus heading and borders?

Tags:

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?

like image 561
Mocco Avatar asked Feb 24 '11 15:02

Mocco


People also ask

How do I resize a form in Visual Studio?

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.

How do you make a form resizable in C#?

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".

What is client area of the 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.

Is used to set the position of form at run time view?

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.


2 Answers

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);
    
like image 74
Yetti Avatar answered Sep 18 '22 13:09

Yetti


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.

like image 39
dandan78 Avatar answered Sep 19 '22 13:09

dandan78