我为MDI Child ovveride
举办了onResize
活动Form
,这是代码:
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
if (WindowState == FormWindowState.Maximized)
{
WindowState = FormWindowState.Normal;
Height = MdiParent.ClientSize.Height - 70;
Width = MdiParent.ClientSize.Width - 10;
Location = new Point(0, 0);
}
}
当用户点击Maximize
上的Form
按钮时,我会设置"标准"尺寸。
所以它看起来像这样......
如何将按钮Maximize
更改为Restore
,因为它已达到我设定的最大尺寸?
答案 0 :(得分:1)
有三种方法可以实现响应式Windows应用程序:
尝试使用拆分容器面板(适用于信息,MSDN Info)
使用Anchor(YouTube link)
使用以下代码
private Size oldSize;
protected override void OnResize(System.EventArgs e)
{
base.OnResize(e);
foreach (Control cnt in this.Controls)
{
ResizeAll(cnt, base.Size);
}
oldSize = base.Size;
}
private void ResizeAll(Control cnt, Size newSize)
{
int iWidth = newSize.Width - oldSize.Width;
cnt.Left += (cnt.Left * iWidth) / oldSize.Width;
cnt.Width += (cnt.Width * iWidth) / oldSize.Width;
int iHeight = newSize.Height - oldSize.Height;
cnt.Top += (cnt.Top * iHeight) / oldSize.Height;
cnt.Height += (cnt.Height * iHeight) / oldSize.Height;
}
在windows form-resize事件中调用此事件。