Skip to main content
A newer version of this page is available. .

Default Size Constraints

  • 2 minutes to read

If the LayoutControlItem.SizeConstraintsType property is set to Default, layout items and their controls are resized according to specific default size constraints. These constraints are dependant on the type of control the layout item displays.

Default Size Constraints

You can customize default size constraints using one of two approaches:

  1. Set the Control.MinimumSize and Control.MaximumSize properties of embedded controls;

  2. Implement the IXtraResizableControl interface for an embedded control.

    The interface members provide the necessary information on how the control will be represented within the Layout Control. Here is the interface’s declaration:

    public interface IXtraResizableControl {
       Size MinSize { get; }
       Size MaxSize { get; }
       event EventHandler Changed;
       bool IsCaptionVisible { get; }
    }
    

Most DevExpress WinForms controls implement the IXtraResizableControl interface to return specific default size constraints. You can also implement this interface for your own controls if required.

Take note of how the default maximum size constraint is calculated. If a control implements the IXtraResizableControl interface and you also set the Control.MaximumSize property, the resulting default maximum size constraint will be calculated according to the OptionsView.ControlDefaultMaxSizeCalcMode property. By default, this property is customized to suit most scenarios (e.g., you have the ability to restrict the maximum width, without affecting the maximum height).

Default Size Constraints for Standard WinForms Controls

One additional, though less common way to set default size constraints for controls is using the LayoutControl’s ConstraintsManager object. The ConstraintsManager contains a table of constraints for a number of standard WinForms controls. You can also add size constraints for your own control type if needed.

Currently, the size constraints are registered for the following standard controls: Button, CheckBox, CheckedListBox, ComboBox, DateTimePicker, DomainUpDown, Label, LinkLabel, ListBox, ListView, MonthCalendar, NumericUpDown, ProgressBar, RadioButton, RichTextBox, TabControl, TextBox, TrackBar, TreeView.

To register default size constraints for your control, use the ConstraintsManager.RegisterControlConstraints method, which is declared as follows.

public void RegisterControlConstraints(Type type, Size minSize, Size maxSize, bool IsCaptionVisible);
See Also