【问题标题】:C# Restore size of FormC# 恢复表单的大小
【发布时间】:2016-02-24 09:16:57
【问题描述】:

我有 ovveride 事件 onResize 用于 MDI Child 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);
    }
}

当用户单击Form 上的按钮Maximize 时,我将设置一个“标准”尺寸。 所以它看起来像这样

我如何将按钮 Maximize 更改为 Restore,因为它已达到我设置的最大尺寸?

【问题讨论】:

  • 你不能。仅当您的表单 WindowState == FormWindowState.Maximized 时,才会显示恢复按钮。您正在处理程序中将其设置回 FormWindowState.Normal。
  • @aschoenebeck - 我将它设置为 FormWindowState.Normal 因为否则 MDI 子窗体的菜单与 Parent 的菜单相交

标签: c# forms winforms resize mdichild


【解决方案1】:

有三种方法可以实现响应式 Windows 应用程序:

  1. 尝试使用拆分容器面板(有关信息,MSDN Info

  2. 通过使用锚 (YouTube link)

  3. 使用以下代码

                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 事件上调用此事件。

【讨论】:

  • 这不是我问的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-05
  • 2010-09-10
  • 2016-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多