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

Custom Size Constraints

  • 3 minutes to read

The default size constraints limit a layout item’s size. This topic describes how to override the default size constraints by imposing custom size limitations at design time and runtime.

Customize Size Constraints via the Menu

A layout item’s Context Menu contains commands to apply and remove size constraints:

Tip

This context menu is available at design time and in runtime customization mode. To invoke runtime customization mode, an end-user can activate the Customization Form.

Example - Lock a layout item’s size at design time

Assume that a form is filled with a LayoutControl that contains three layout items:

  • an item that displays a memo editor
  • an item that contains a button
  • an Empty Space Item (to the left of the button)

LockSizeEx_10_OriginalLayout

When the form is resized, all the items are resized proportionally:

LockSizeEx_15_ButtonResized

The steps below show how to lock the size of the layout item that hosts the button.

  1. Apply the Free Sizing command to the target layout item.

    LockSizeEx_20_FreeSizingMenu

  2. Resize this layout item on the form, so that it takes the required size.

    LockSizeEx_22_ResizeButton

  3. Apply the Lock Size command.

    LockSizeEx_25_LockSizeMenu

Now when the form is resized, the button retains its original size:

LockSizeEx_30_FinalResult

The following table describes commands available in the Size Constraints menu.

Command

Description

ResetToDefault Reset to default

Applies the default size constraints to the item, as described in the Default Size Constraints topic.

This command sets the layout item’s LayoutControlItem.SizeConstraintsType to Default.

FreeSizing Free sizing

Unlocks the upper limits of the item’s width and height that are specified by the MaxSize properties.

This command sets the layout item’s LayoutControlItem.SizeConstraintsType to Custom. The MaxSize.Width and MaxSize.Height properties are set to 0. The MinSize property is set to the default minimum (the same value as in the Default size constraints mode).

LockSize Lock Size

Locks the layout item’s current size, so the layout item can no longer be resized.

This command sets the LayoutControlItem.SizeConstraintsType to Custom. The MaxSize and MinSize properties are set to the value specified by the layout item’s BaseLayoutItem.Size property.

LockWidth Lock Width

Locks the layout item’s current width.

This command sets the LayoutControlItem.SizeConstraintsType to Custom. The MaxSize.Width and MinSize.Width properties are set to the value specified by the layout item’s Size.Width property. The MaxSize.Height and MinSize.Height properties remain unchanged.

LockHeight Lock Height

Locks the layout item’s current height.

This command sets the LayoutControlItem.SizeConstraintsType to Custom. The MaxSize.Height and MinSize.Height properties are set to the current height specified by the layout item’s Size.Height property. The MaxSize.Width and MinSize.Width properties remain unchanged.

Custom Size Constraints

To provide custom size constraints for a layout item in code, do the following:

Demo

Custom size constraints

Example - Lock a layout item’s size

DevExpress.XtraLayout.LayoutControlItem item = layoutControlItemButton;
item.SizeConstraintsType =  DevExpress.XtraLayout.SizeConstraintsType.Custom;
Size newSize = new Size(105, 41);
item.MaxSize = newSize;
item.MinSize = newSize;

Apply size constraints to embedded controls

You can apply size constraints to a control that hosts within a layout item. This can be helpful when you need to custom align the control within the client area. See Aligning Controls Within Layout Items for more information.

See Also