
Control Layout Properties
As you have seen, each panel has a default mode of positioning child elements. Consider the following:
• The Canvas only makes an element big enough to hold its content unless you define Height and
Width values.
• Other panels will ‘stretch’ elements within their frames.
All controls inherit from the Control base class a set of properties that allow for fine tuning their placement
within a panel.
• HorizontalAlignment / VerticalAlignment: Used to determine how to position a control when
there is extra space available.
• Margin: Adds space around the element.
• MinWidth / MinHeight / MaxWidth / MaxHeight: Sets an absolute minimum or maximum size
for height and width.
While many of these properties are self-explanatory, Margin deserves special mention. Set a control’s
Margin property when you wish to add some ‘white space’ around each side of the element. This will
prevent controls from resting side by side against each other.
Consider the updated internal StackPanel of the previous markup. Note the use of Margin on the final
Button. This adds a ‘padding’ thickness of 5 to each side of the button.
<StackPanel Background="LightSteelBlue"
Orientation="Vertical" DockPanel.Dock="Left">
...
<Button Name="btnOK" Margin="10">OK</Button>
</StackPanel>
Now that you have learned the basics of working with panels, you can turn your attention to details of the
controls they contain. Again, consult the .NET Framework SDK documentation for complete details of the
controls that interest you. You will see many controls at work during your lab time.
Control Layout Properties
Table of Contents
Copyright (c) 2008. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an
online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.
Courseware
Training Resources
Tutorials
Services