[英]Form.DesktopBounds.Width seems to be off by 10 pixels. How to determine correct form width?
When accessing the Form.DesktopBounds.Width property it seems to be off by 10 pixels. 当访问Form.DesktopBounds.Width属性时,它似乎偏离了10个像素。 It also seems that the window border is 5 pixels on each side. 似乎窗口边框的每一侧都是5像素。 How can I determine the correct form width, including the border around the form. 如何确定正确的表单宽度,包括表单周围的边框。
According to the documentation , if you want to get the size and location of the control including its nonclient elements, you just want to use Form.Bounds
. 根据文档 ,如果要获取控件的大小和位置( 包括其非客户端元素),则只想使用Form.Bounds
。 In the case of width, that would be Form.Bounds.Width
. 如果为width, Form.Bounds.Width
。
I believe my comment suggestion of Form.Width
will work as well, since Top
, Left
, Width
, and Height
all come from the Bounds
themselves. 我相信我对Form.Width
建议Form.Width
将起作用,因为Top
, Left
, Width
和Height
都来自Bounds
本身。
I just ran into this problem. 我只是遇到了这个问题。
I get the "off by 10" numbers from Form.Height
and from Form.Bounds.Height
. 我从Form.Height
和Form.Bounds.Height
获得“ Form.Height
10”的数字。 The height values are correct on Windows XP, but off by 10 on Windows 7. ( Width
values are also off.) 高度值在Windows XP上是正确的,但在Windows 7上是10。( Width
值也处于关闭状态。)
When the FormBorderStyle
is Sizable
then the values are correct. 当FormBorderStyle
Sizable
则值是正确的。 But when it is FixedToolWindow
I get the off-by-10 values. 但是当它是FixedToolWindow
时,我得到的是10倍的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.