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

LayoutControl Class

Creates and maintains a consistent layout of controls. See Layout and Data Layout Controls.

Namespace: DevExpress.XtraLayout

Assembly: DevExpress.XtraLayout.v18.1.dll

Declaration

[ToolboxTabName("DX.18.1: Navigation & Layout")]
[ProhibitUsingAsDockingContainer]
[ToolboxBitmap(typeof(LayoutControl), "Images.layoutControl256.bmp")]
public class LayoutControl :
    ContainerControl,
    ILayoutControlOwner,
    IComponent,
    ISupportImplementor,
    IToolTipControlClient,
    ISupportInitialize,
    IXtraSerializable,
    IXtraSerializableLayout,
    IExtenderProvider,
    ISupportLookAndFeel,
    ILayoutControl,
    IStyleController,
    ILayoutDesignerMethods,
    IPrintable,
    IBasePrintable,
    IControlIterator,
    IDisposable,
    IDragDropDispatcherClient,
    ITransparentBackgroundManager,
    ITransparentBackgroundManagerEx,
    IXtraResizableControl,
    IMouseWheelSupport,
    ISupportXtraSerializer,
    IGestureClient,
    ILayoutControlOwnerEx,
    ITemplateManagerImplementor,
    IDXMenuManagerProvider,
    IFilteringUIProvider

The following members accept/return LayoutControl objects:

Remarks

Layout Control allows you to arrange any controls within a form without overlapping and misaligning them. See the Layout Control topic to learn the advantages of using the Layout Control. To learn how to create and customize a layout of controls at design time, refer to Design-Time Customization .

A LayoutControl object is visually presented by a root group (LayoutControl.Root) which is a container whose only purpose is to display other items, groups and tabbed groups.

The following items are basic elements for building a layout of controls.

  • LayoutControlItem - a regular layout item that can display an external control;
  • LayoutControlGroup - a regular container that can display other items, regular and tabbed groups;
  • TabbedControlGroup - a tabbed group whose elements (regular groups) are rendered as tabs.

The following image shows a form with a Layout Control. The Employee root group displays two regular layout items (Job Title and Contact Name), regular group (Personal Info) and a tabbed group. The latter has two tabs containing two groups - Photo and Notes, respectively.

LayoutControl_structure

To access the Layout Control’s items in code, use the LayoutControl.Items collection.

To add a new item, group or tabbed group to another group via code, use the LayoutControlGroup.AddItem, LayoutControlGroup.AddGroup and LayoutControlGroup.AddTabbedGroup methods respectively. To move an existing item, group and tabbed group to a new position, use its BaseLayoutItem.Move method.

Example

The following example shows how to create a LayoutControl control and add layout items to it.

The example shows different ways to add visible and hidden layout items to the Layout Control.

CreateLayoutItems_ex

Note

To allow a Layout Control’s layout to be customized and serialized, ensure that the Name properties of the layout items and their controls are set to unique values. The control’s Name property must be initialized before this control is assigned to the LayoutControlItem.Control property.

using DevExpress.XtraLayout;
using DevExpress.XtraEditors;

LayoutControl lc = new LayoutControl();
lc.Dock = System.Windows.Forms.DockStyle.Fill;
this.Controls.Add(lc);

//Create a layout item and add it to the root group.    
LayoutControlItem item1 = lc.Root.AddItem();
// Set the item's Control and caption.
item1.Name = "Layout Item 1";
Control textBox1 = new TextEdit();
textBox1.Name = "TextBox1";
item1.Control = textBox1;
item1.Text = "Name";

// Create a new layout item.
LayoutControlItem item2 = new LayoutControlItem();
// Add the item to the root group by setting its parent.
item2.Parent = lc.Root;
item2.Name = "Layout Item 2";
Control textBox2 = new TextEdit();
textBox2.Name = "TextBox2";
item2.Control = textBox2;
item2.Text = "E-mail";

// Create a hidden layout item.
LayoutControlItem item3 = new LayoutControlItem();
item3.Name = "Layout Item 3";
lc.HiddenItems.AddRange(new BaseLayoutItem[] { item3 });
Control textBox3 = new MemoEdit();
textBox3.Name = "TextBox3";
item3.Control = textBox3;
item3.Text = "Notes";

The following code snippets (auto-collected from DevExpress Examples) contain references to the LayoutControl class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also