Windows窗体的大小是否包括其边框? [英] Does the size of a Windows Form include its Border?

查看:59
本文介绍了Windows窗体的大小是否包括其边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您设置Windows窗体的大小时,即;

When you set the size of a windows form, ie;

Form1.Size = new System.Drawing.Size(700, 500);

这是否包括Windows围绕表单放置的边框?因为我已通过表单将700x500的图像(通过pictureBox)添加到了我的表单中,并且已被边框切除.

Does this include the border which windows puts around the form? Because I have added images (via pictureBoxes) which are 700x500 to my form, and they have been cut off by the border.

另外:当我说边框时,我指的是默认的Windows边框,您可以拖动它的边缘来调整其大小,并包含红色的X,Minimize和Maximize按钮.

Also: When I say the border, I mean the default windows border which you can drag the edges of to resize it, as well as contain the red X, Minimize, and Maximize buttons.

推荐答案

这取决于例如以.NET 4.5为目标时的大小.总是包含边框,但您实际上并不知道包含多少边框. Aero带来的胖边界和XP带来的瘦边界问题.

That depends, you'll get a different size when you target .NET 4.5 for example. The border is always included but you don't really know how much of the border is included. An issue with the fat borders you get with Aero and the skinny ones you get in XP.

这几乎总是错误的做法.您始终想分配 ClientSize 属性.重要提示,它不包含边框,因此可以确保控件仍然适合.

It is almost always the wrong thing to do. You always want to assign the ClientSize property instead. Important, it doesn't include the borders so you can be sure that controls still fit.

硬编码的大小也总是错误的.您的表单将重新缩放,具体取决于视频适配器的每英寸点数设置. DPI设置越大,则仍需要适合其内容的表单越大.因此正确的陈述应类似于此:

And hard-coding the size is always wrong as well. Your form will be rescaled, depending on the video adapter's dots-per-inch setting. The larger the DPI setting, the bigger the form needs to be to still fit its content. So the correct statement ought to resemble this:

  this.ClientSize = new Size(PictureBox3.Right, PictureBox3.Bottom);

假设"PictureBox3"是要保持可见的最右下角的控件.该语句需要出现在Load事件处理程序中,以确保已完成重缩放,但该语句不能在构造函数中使用.使用Load事件的极少数理由之一.

On the assumption that "PictureBox3" is the control in the far right-bottom corner that you want to keep visible. This statement needs to appear in the Load event handler to ensure that rescaling was done, it can't work in the constructor. One of the very few good reasons to use the Load event.

这篇关于Windows窗体的大小是否包括其边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆