如何在设计时将表单的大小填满整个屏幕?

问题描述 投票:0回答:1

如何点击(不按尺寸,如何使表格填满整个屏幕)全屏显示,例如f11)。在设计时-时间(后面没有代码)?

c# winforms size design-time
1个回答
0
投票

在设计时,使用定义为Maximized的WindowsState属性。

在运行时,您可以使用此:

static public class FormHelper
{
  static public void SetSizeToScreen(this Form form)
  {
    int left = Screen.PrimaryScreen.Bounds.Left;
    int top = Screen.PrimaryScreen.Bounds.Top;
    int width = Screen.PrimaryScreen.Bounds.Width;
    int height = Screen.PrimaryScreen.Bounds.Height;
    form.Location = new Point(left, top);
    form.Size = new Size(width, height);
  }

  static public void SetSizeToDesktop(this Form form)
  {
    int left = SystemInformation.WorkingArea.Left;
    int top = SystemInformation.WorkingArea.Top;
    int width = SystemInformation.WorkingArea.Width;
    int height = SystemInformation.WorkingArea.Height;
    form.Location = new Point(left, top);
    form.Size = new Size(width, height);
  }
}

用法:

this.SetSizeToDesktop();
© www.soinside.com 2019 - 2024. All rights reserved.