Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How can I vertically-align autosizing buttons?

Here is the scenario:

Simply setting Button.AutoSize=true on each button will break your alignment, since the localized strings are likely to be different lengths - so you'd get this:

The solution is to place the three (or however many) buttons (or whatever controls) in a vanilla, non-flow or table Panel* like this:

and anchor the buttons Left and Right. Then set the Panel to AutoSize, and when the text is changed, causing the buttons to adopt different lengths, the largest button "pushes" the Panel to the size it needs, and the anchors on the other (smaller) buttons "pulls" the smaller buttons to the same size, ala:



Page view counter