How do I keep my winforms controls from overlapping when I expand the application?
Asked Answered
S

2

5

I have a pretty simple winforms application. It contains a rich edit box, embedded browser, progress bar, a few buttons etc.

I have the anchors on the controls set to expand in all directions.

When expanding up and down, however, the controls will overlap one another. How do I prevent this from happening?

Thanks

Samora answered 3/1, 2013 at 21:2 Comment(4)
Have you tried docking your controls?Compendium
@Compendium when I set dock it will immediately overlap the other controls on the form.Samora
Okay, I see. You'll probably be able to achieve what you want by modifying the order of your UI elements in the Document Outline window (View => Other Windows). In the Windows Forms editor, the order of controls matters during the layout process.Compendium
You can't set all controls to expand in all directions by anchoring them on 4 sides - this ties them to the parent form's sides and as you resize they'd overlap. Consider grouping them in panels or other controls so you have fewer direct children of the form; make the form's children resize appropriately then go to their childrenBenkley
M
17

Your best bet is to add a TableLayoutPanel to your form which contains the "layout grid" this should be docked to the form, then you can add your controls into the cells in the table (they can cover multiple rows and columns so you can get the layout you want).

Morelock answered 3/1, 2013 at 21:14 Comment(0)
M
0

You must set the property Autosize=true on every control, especially on the main form.

Note that some controls like TabControl have this property, but you can't see it with intellisense (Attribute Browseable=false).

Mccarthyism answered 3/1, 2013 at 21:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.