How do I set the size of the visible area of a for

2020-01-29 08:32发布

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?

3条回答
来,给爷笑一个
2楼-- · 2020-01-29 09:05

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.

查看更多
我命由我不由天
3楼-- · 2020-01-29 09:13

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);
    
查看更多
Rolldiameter
4楼-- · 2020-01-29 09:13

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

查看更多
登录 后发表回答