代码之家  ›  专栏  ›  技术社区  ›  Muhammad Faizan Khan

WinForm正在以比屏幕大的尺寸打开

  •  1
  • Muhammad Faizan Khan  · 技术社区  · 6 年前

    我有一个窗口窗体,这里是它的主要属性

    1. windows状态 maximized
    2. true
    3. GrowAndShrink

    它在我的电脑上运行良好(以最大尺寸打开,根据屏幕大小而定),但当我在另一台电脑上尝试此应用程序时,窗体大小以大尺寸打开。它是最大化的,但它的控制是大尺寸的。 我做错什么了?

    请记住有两个附加的屏幕,我在表单中准确地提到(在表单加载事件中)它使用此代码片段在特定的屏幕中打开。

      int displayScreen = GetScreenNumber();
      this.Location = Screen.AllScreens[displayScreen].WorkingArea.Location;
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Suraj Kumar zip    6 年前

    您可以设置窗体的最小和最大大小,如下所示

    this.MinimumSize = new Size(140, 480);
    this.MaximumSize = new Size(140, 480);
    

    private void Form1_Load(object sender, EventArgs e)
            {
                int h = Screen.PrimaryScreen.WorkingArea.Height;
                int w = Screen.PrimaryScreen.WorkingArea.Width;
                this.ClientSize = new Size(w, h);
            }
    

    Rectangle screen = Screen.PrimaryScreen.WorkingArea;
    int w = Width >= screen.Width ? screen.Width : (screen.Width + Width) / 2;
    int h = Height >= screen.Height ? screen.Height : (screen.Height + Height) / 2;
    this.Location = new Point((screen.Width - w) / 2, (screen.Height - h) / 2);
    this.Size = new Size(w, h);