-1

How can I resize all of a Windows Forms form contents when changing resolution, cos it looks like the following?

Enter image description here

I want to make that when I change size of window that everything stays where it is when I open the program, so that those things get bigger and moves to right side.

BTW, I'm new to Visual Studio and C#, so my explanation is probably not the best :D

I get it :D

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nufflee
  • 39
  • 2
  • 9
  • What do you mean resolution and why should it be affecting your positioning. Have you tried with autosizing or anchor settings? – D. Petrov Jun 27 '16 at 09:42
  • @VitoGaming Have you tried the `Dock` and `Anchor` properties. –  Jun 27 '16 at 09:43
  • You may find your answer here, and use dock and anchor properties. [detect-change-of-resolution-c-sharp-winforms](http://stackoverflow.com/questions/442337/detect-change-of-resolution-c-sharp-winforms/) – Nam Tran Jun 27 '16 at 09:55

1 Answers1

2

Anchor is your friend.

If you look you will see that all the controls have an anchor property. Anchor fixes the distance from the border of the control to that side of the parent (The form usually).

For default controls are anchored to the top and the left, meaning they will maintain the distance to the top and the left borders of the form, and ignorin if it gets big.

If you anchor somehing to the bottom and rigth it will stay at the same distance from the rigth and botton borders, moving when you resize the form. Thats usefull for when you need something in the down right corner (An accept button, for example)

Now the interesting part is that if you anchor something to two oposite sides (top and bottom or right and left) it will maintain its distance to both borders. And what happens if the borders distance themselves? the control grow.

So you need to play with it, see what controls do you want anchored where, wich one to grow and wich ones to stay still.

In your caseI would set the labels to be anchored top and left and the textboxes to be anchored top, right and left. So they will expand to the right when the form is resized.

Aimnox
  • 895
  • 7
  • 20