Take Control of Window Layout
.NET 2.0 includes two new container controls that can lay
out all the controls they contain in a set pattern. Both of these
controls extend the Panel
class with
additional layout logic. The FlowLayoutPanel
arranges controls evenly over
several rows (from left to right), or in multiple columns (from top to
bottom). The TableLayoutPanel
places
its controls into a grid of invisible cells, allowing to you to keep
consistent column widths and row heights.
Note
The new . NET layout controls give you a way to lay out controls in set patterns automatically, which can save a good deal of effort with highly dynamic or configurable interfaces.
How do I do that?
The layout controls are used most often in the following two scenarios:
You have a dynamic interface that generates some of its elements programmatically. Using the layout controls, you can arrange a group of controls neatly without calculating a position for each control (and then setting the
Location
property accordingly).You have a localized interface that must adapt to different languages that require vastly different amounts of on-screen real estate. As a result, when the display text changes, the controls must also adjust their size. In this case, layout controls can help you make sure the controls remain properly arranged even when their size varies.
Example 3-4 demonstrates
an implementation of the first scenario. It starts with a form that
includes an empty FlowLayoutPanel
.
The FlowLayoutPanel
has ...
Get Visual Basic 2005: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.