Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fit/re-size Windows Form to any screen resolution?

Tags:

c#

winforms

I know this is duplicated question but I checked all other related question and their answers did not help ( the result still the same as shown in screenshot 2)

screenshot1

I am new to c# windows forms. As shown in screenshot1, I have Form1 with some controls and each group of controls were put in a panel. I designed the application in PC1 as shown in Screenshot1 which is fit the screen resolution and worked well.

Screenshot2

My application was developed in 1366 x 768 screen resolution (as shown in Screenshot1) but when I run this application in different computer (PC2) with different monitor size and different screen resolution the form appeared too big and part of the application is missing or is out of the screen.

However I solved this issue using Anchors but another issues came up which is: the user control does not re-size itself ( as shown in screenshot2) and part of it is cut or went under panel1 . I do not know if the problem is related to user control or related to all controls in Form1 (they should resize themselves)

I even tried the following code but the result still the same:

this.WindowState = FormWindowState.Maximized;
this.Location = new Point(0, 0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
Screen.PrimaryScreen.WorkingArea

I have been searching to solve this issue the whole day yesterday but I failed, Please help me with any idea/suggestion it might work. Thank you

like image 459
Kate Avatar asked Jan 06 '23 15:01

Kate


1 Answers

If you are working with Windows Forms and you cannot switch to WPF then you will prefer to do all the design in the lowest resolution at which you must run.

In WinForms you are setting the Size of every element so they will not re size according to the app size. What they will do is to be distributed along the empty space (if you program them to do so) increasing the free space between them, that's all.

Another option are LayoutPanels as Sinatr said as they try to offer the WPF panel functionality.

like image 57
Ignacio Soler Garcia Avatar answered Jan 09 '23 04:01

Ignacio Soler Garcia