How to fit Windows Form to any screen resolution?

后端 未结 8 920
长情又很酷
长情又很酷 2020-12-13 18:22

I work on VS 2008 with C#. This below code does not work for me. My form was designed in 1024 x 768 resolution.

Our clients laptop is in 1366 x 768 resolution. To so

相关标签:
8条回答
  • 2020-12-13 18:43

    simply set Autoscroll = true for ur windows form.. (its not good solution but helpful)..

    try for panel also(Autoscroll property = true)

    0 讨论(0)
  • 2020-12-13 18:45

    You can simply set the window state

    this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
    
    0 讨论(0)
  • 2020-12-13 18:47

    Set the form property to open in maximized state.

    this.WindowState = FormWindowState.Maximized;
    
    0 讨论(0)
  • 2020-12-13 18:54

    Can't you start maximized?

    Set the System.Windows.Forms.Form.WindowState property to FormWindowState.Maximized

    0 讨论(0)
  • 2020-12-13 18:55

    If you want to set the form size programmatically, set the form's StartPosition property to Manual. Otherwise the form's own positioning and sizing algorithm will interfere with yours. This is why you are experiencing the problems mentioned in your question.

    Example: Here is how I resize the form to a size half-way between its original size and the size of the screen's working area. I also center the form in the working area:

    public MainView()
    {
        InitializeComponent();
    
        // StartPosition was set to FormStartPosition.Manual in the properties window.
        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);
    }
    

    Note that setting WindowState to FormWindowState.Maximized alone does not change the size of the restored window. So the window might look good as long as it is maximized, but when restored, the window size and location can still be wrong. So I suggest setting size and location even when you intend to open the window as maximized.

    0 讨论(0)
  • 2020-12-13 18:55
    int h = Screen.PrimaryScreen.WorkingArea.Height;
    int w = Screen.PrimaryScreen.WorkingArea.Width;
    this.ClientSize = new Size(w , h);
    
    0 讨论(0)
提交回复
热议问题