1

I have a window form and here its main property

  1. windows state to maximized
  2. Auto size true and
  3. AutoSizeMode set to GrowAndShrink

It is working fine (opening in maximized size, fit according to screen) in my PC but when i am trying this application into another PC the form size opening in large size. It is maximized but its controls are in large size. Whats i am doing wrong?

Remember there are two screens attached and I have precisely mention (in Form load event) to my form that it open in specfic screen using this code snippet.

  int displayScreen = GetScreenNumber();
  this.Location = Screen.AllScreens[displayScreen].WorkingArea.Location;
Muhammad Faizan Khan
  • 10,013
  • 18
  • 97
  • 186
  • 1
    Is you application DPI-Aware (set in the `app.manifest` or by other means)? If not, the Window is automatically virtualized. Does it also look somewhat *blurry*? – Jimi Oct 26 '18 at 14:15
  • Frequent flyer [here](https://stackoverflow.com/questions/13228185/how-to-configure-an-app-to-run-correctly-on-a-machine-with-a-high-dpi-setting-e?answertab=active#tab-top). [Some notes I've written](https://stackoverflow.com/questions/50239138/dpi-awareness-unaware-in-one-release-system-aware-in-the-other?answertab=active#tab-top). – Jimi Oct 26 '18 at 14:28
  • This is entirely normal, the monitor on that machine has a lower resolution. The window is a lot bigger as well, but you can't see that because you maximized it. Programmers tend to have nice high resolution screens, that doesn't exactly help them create UI that scales well. – Hans Passant Oct 26 '18 at 14:29

1 Answers1

3

You can set the minimum and maximum size of form as shown below

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

You can also use it as below

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);
        }

Another way it can work for you is the

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);
Suraj Kumar
  • 5,547
  • 8
  • 20
  • 42