C4d*_*C4d 4 c# size border winforms formborderstyle
是否有任何文件证明正则格式的边框有多厚?
目标:
我创建了一个宽度为800px的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();
}
Run Code Online (Sandbox Code Playgroud)
我的意思是您的代码对我来说看起来很合逻辑。但是结果仍然是一样的。该userControl
显示一点点小。我知道我已经dock = fill
在我的按钮没有被专业放置在布局中的地方使用过。但是,除此以外,必须有一个解决方案来设置正确的大小。
看来您正在寻找
int thickness = SystemInformation.Border3DSize;
Run Code Online (Sandbox Code Playgroud)
另一个(也是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));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7611 次 |
最近记录: |