4

是否有任何文档说明常规形式的边框有多厚?

目标:
我创建了一个宽度为 800 像素的 userControl。我想用全分辨率(800px - 一切可见)的新实例引发一个弹出窗口(通常是正常形式)。

我的问题: 将表单设置为Form.Size.Width = 800不会这样做。看起来表单的边框包含在表单的宽度属性中。我需要减去那个边界。

我应该是这样的: 2px + 800px + 2px

如果你想看一些代码告诉我,但我认为这里没有必要。

编辑

在此处输入图像描述

弹出控件后:

在此处输入图像描述

弹出代码:

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();
}

我的意思是你的代码在我看来是合乎逻辑的。但结果还是一样。显示的userControl有点小。我知道我已经使用dock = fill了我的按钮没有专业放置在布局内的地方。但除此之外,必须有一个解决方案来设置正确的大小

4

1 回答 1

4

看来您正在寻找

int thickness = SystemInformation.Border3DSize;

另一种(并且,INHO,更好的)可能性是使用ClientRectangle控件。例如:

// 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));
于 2015-08-20T08:08:45.323 回答