Reputation: 55
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.
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.
Upvotes: 2
Views: 9602
Reputation: 208
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#?
Upvotes: 1
Reputation: 1294
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.
Upvotes: 0