none
How to scale controls' size/position in various screen resolution in WinForm RRS feed

  • Question

  • I designed the screen of my program from hi-resolution screen.

    It shows all controls from hi-resolution screen.

    However some controls are cut from low-resolution.

    How to resize/reposition controls from various resolution screen?

    Should I iterate all controls by various resolutions?

    (My program is made by WinForm.


    • Edited by Jeff0803 Monday, December 2, 2019 3:15 PM
    • Moved by CoolDadTx Monday, December 2, 2019 6:34 PM Winforms related
    Monday, December 2, 2019 3:14 PM

Answers

  • Hi Jeff0803,
    First, you should change the AutoScaleMode of Form to the Dpi which specifies the different types of automatic scaling modes supported by Windows Forms.
    Then you can try to use Dock and Anchor properties to auto resize and adjust Form controls.
    Here is a code example about using anchor properties and you can refer to it.

    public Form1()
    {
        InitializeComponent();
        AddControls();
    }
    private void AddControls()
    {
        Button button1 = new Button();
        TextBox textBox1 = new TextBox();
        textBox1.Location = new Point(50, 50);
        textBox1.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
        button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
        button1.BackColor = Color.Red;
        button1.Click += new System.EventHandler(this.button1_Click);
        this.Controls.Add(button1);
        this.Controls.Add(textBox1);
    }

    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Jeff0803 Friday, December 6, 2019 5:57 PM
    Tuesday, December 3, 2019 6:03 AM
  • Hi Jeff,

    I'm afraid it is somewhat distant idea that we resize/locate according to screen resolution, because so many monitors/resolution are used.
    You need to focus on the minimum (I suppose it's 1024 x 768, nowadays) and to put all controls within it.

    If you're talking about DPI, please make your program with DPI-Aware.
    1) menu [Project] > [Add New Item] > select [Application Manifest File]
    2) (in app.mamnifest) modify like this (remove comment of <application xmlns=.... >)

    3) Make your Windows Form.AutoSceleMode = Dpi
      
    Regards,

    Ashidacchi -- http://hokusosha.com

    • Marked as answer by Jeff0803 Friday, December 6, 2019 6:00 PM
    Thursday, December 5, 2019 3:22 AM

All replies

  • Hi Jeff0803,
    First, you should change the AutoScaleMode of Form to the Dpi which specifies the different types of automatic scaling modes supported by Windows Forms.
    Then you can try to use Dock and Anchor properties to auto resize and adjust Form controls.
    Here is a code example about using anchor properties and you can refer to it.

    public Form1()
    {
        InitializeComponent();
        AddControls();
    }
    private void AddControls()
    {
        Button button1 = new Button();
        TextBox textBox1 = new TextBox();
        textBox1.Location = new Point(50, 50);
        textBox1.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
        button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
        button1.BackColor = Color.Red;
        button1.Click += new System.EventHandler(this.button1_Click);
        this.Controls.Add(button1);
        this.Controls.Add(textBox1);
    }

    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Jeff0803 Friday, December 6, 2019 5:57 PM
    Tuesday, December 3, 2019 6:03 AM
  • Hi Jeff,

    I'm afraid it is somewhat distant idea that we resize/locate according to screen resolution, because so many monitors/resolution are used.
    You need to focus on the minimum (I suppose it's 1024 x 768, nowadays) and to put all controls within it.

    If you're talking about DPI, please make your program with DPI-Aware.
    1) menu [Project] > [Add New Item] > select [Application Manifest File]
    2) (in app.mamnifest) modify like this (remove comment of <application xmlns=.... >)

    3) Make your Windows Form.AutoSceleMode = Dpi
      
    Regards,

    Ashidacchi -- http://hokusosha.com

    • Marked as answer by Jeff0803 Friday, December 6, 2019 6:00 PM
    Thursday, December 5, 2019 3:22 AM