2

I was working on a Windows Forms application today that was functioning correctly. When I changed the font size of some buttons, textboxes and labels the form zoomed in and now it is far too big on runtime, and I can't figure out how to change the size back.

Form Designer

The first image shows the form designer and the second shows the form running hard to show as it is bigger than the screen size.

Form when running

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Besty
  • 55
  • 1
  • 5

2 Answers2

1

You should change the size value or ClientSize of the form,

this.Size = new Size(200, 200);

or

this.ClientSize = new Size(200, 200);

Or you can view the form in Visual Studio and click on the side of it and play with its size.

See: How do I resize a Windows Forms form in C#?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
iamanoob
  • 208
  • 3
  • 13
  • thank you, both of these reduce the form size however now most of my controls are off screen. Not sure what is wrong as I thought I had only changed some font sizes – Besty Mar 31 '16 at 13:32
  • @Besty You should really use the Form Designer, you'll see what's up – iamanoob Mar 31 '16 at 13:38
  • thanks for your help I cant see anything wrong in the designer it is almost like the form is zooming in as it opens – Besty Mar 31 '16 at 13:43
  • @Besty could you post a screenshot of the form designer and the "zoomed" form ? I'm curious to see. – iamanoob Mar 31 '16 at 13:44
0

When designing a form, keep in mind that the screen DPI, user font settings (zoom, etc), and other factors can cause a form to change size. It's a good idea to make your forms handle such changes gracefully.

To keep things visible, use layout controls. In the Toolbox, they are under "Containers". Based on your screenshot, I would assume a TableLayoutPanel would work best. You might want to use a SplitContainer that has its Orientation set to Vertical and IsSplitterFixed set to True. You may need to nest some things depending on how exactly you want it laid out.

Once you have done that, you can use the Anchor and Dock properties of the controls to position and size them within the containers.

When all of this is put together, you can resize a form, and the controls will stay in place, move around, change size, and/or do anything else that they and their containers are set to do. No additional coding to control size would be needed.

Chris Fannin
  • 1,284
  • 1
  • 10
  • 16