Autosize contents of form in C# to fit any window size

3.3k views Asked by At

I have written a program in C# (Visual Studio) which makes use of multiple forms. The problem occurs whenever the program is run on a different computer which has a different screen resolution. The contents of the form do not fit into the form whenever the program is run on a computer with a smaller screen resolution. What can I do to make the CONTENTS of the form resize accordingly, depending on the screen resolution so that the contents of the form will always fit, irrelevant of the screen resolution/size of the computer on which it is being run?

Thanks a lot!

1

There are 1 answers

3
Gary On

Assuming you are using WinForms, your best bet in this case is to make use of the various container controls included in the framework, like the FLowLayoutPanel and TableLayoutPanel.

If you want to avoid these, use the standard Panel control and make use of Dock property to ensure it fills the required areas correctly. Then use the Dock property on all your controls to make the layout more responsive to different resolutions, and more importantly different DPI settings in Windows.