Search code examples
c#windowsformsscreenresolution

C# form adjusting screen resolution without sizable


I have created a c# windows forms program with a Form which includes a Diagram, an image and Buttons. When I open the program the Form to big for the computer screen this is because the screen resolution is to big or to small. How can I make the Form exactly right for each screen resolution type whiteout using sizable?


Solution

  • The problem is because you define (Pixel) sizes for your controls and therefore also your Form. You can put your space consuming controls (diagrams, images) into Panels and then set the Dock property appropriately (on the controls and/or the panels) so that they scale out to their maximum size. This way you can reduce the size of the Form and because you define ratios rather than pixel numbers the controls/labels will expand as needed. Depending on how you want it to look like you will have to play with different configurations (one or two controls in one label and then setting dock either to fill or left/right/top/bottom). There's also the SplitContainer control to help you achieve certain design goals.

    Additionally, if you always want the perfectly scaled window, open the form in Maximised mode:

    this.WindowState = System.Windows.Forms.FormWindowState.Maximized;