[英]C# Winforms | Form-border thickness
Is there any documentation of how thick a border of a regular form is? 是否有任何关于常规形式边框厚度的文档?
The goal: 目标:
I've created a userControl with a width of 800px. 我创建了一个宽度为800px的userControl。 I want to raise a popup (normal form in general) with a new instance of it at full resolution (800px - everything visible).
我想用一个全分辨率的新实例(800px - 一切可见)来提出一个弹出窗口(一般的普通形式)。
My Problem: Setting the form to Form.Size.Width = 800
wont do it. 我的问题:将表单设置为
Form.Size.Width = 800
不会这样做。 It looks like the border of the form is included in the width-property of the form. 看起来窗体的边框包含在窗体的width属性中。 I need to subtract that border.
我需要减去那个边界。
I should be something like: 2px + 800px + 2px 我应该是这样的: 2px + 800px + 2px
If you would like to see some code tell me, but I think its unnecessary in here. 如果你想看到一些代码告诉我,但我觉得这里没必要。
EDIT : 编辑 :
After popping the control up: 弹出控件后:
Code for popup: 弹出代码:
private void buttonPopup_Click(object sender, EventArgs e)
{
Form MyPopup = new Form();
customControl MyUserControl = new customControl();
MyUserControl.Dock = DockStyle.Fill;
Rectangle rc = MyUserControl.RectangleToScreen(MyUserControl.ClientRectangle);
//int thickness = SystemInformation.Border3DSize.Width;
//MyPopup.MaximumSize = new Size(MyUserControl.Size.Width + (thickness*2), 1500);
MyPopup.Controls.Add(MyUserControl);
MyPopup.MaximumSize = new Size(rc.Width, rc.Height);
MyPopup.Show();
}
I mean your code looks logical to me. 我的意思是你的代码看起来合乎逻辑。 But still the result is the same.
但结果仍然是一样的。 The
userControl
is displayed a tiny bit smaller. userControl
显示的小一点。 I know I've used dock = fill
where my button isnt placed professionally inside the layout. 我知道我已经使用了
dock = fill
,我的按钮没有专业地放置在布局中。 But away from this there has to be a solution to just set the right size . 但远离这一点,必须有一个解决方案,只需设置正确的大小 。
It seems that your are looking for 看来你正在寻找
int thickness = SystemInformation.Border3DSize;
another (and, INHO, a better one) possiblity is to use ClientRectangle
of the control. 另一个(和INHO,一个更好的 )可能性是使用控件的
ClientRectangle
。 For instance: 例如:
// Client rectangle in screen coordinates
Rectangle rc = MyControl.RectangleToScreen(MyControl.ClientRectangle);
// Let's align context menu (its width) to bottom of the control
MyContextMenuStrip.AutoSize = false;
// Depending on actual dropdown control you may want align either via
// Width = rc.Width;
// Or
// ClientSize = new Size(rc.Width, someHeight);
MyContextMenuStrip.Width = rc.Width;
// Let's show context menu at the bottom of the control
MyContextMenuStrip.Show(new Point(rc.Left, rc.Bottom));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.