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

做~自己de王妃 提交于 2019-11-27 14:38:25
Yetti

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!