LayoutControlItem Class

Displays an embedded control and an optional label.

Namespace: DevExpress.XtraLayout

Assembly: DevExpress.XtraLayout.v20.1.dll

Declaration

public class LayoutControlItem :
    LayoutItem,
    IContextItemCollectionOptionsOwner,
    IContextItemCollectionOwner
Public Class LayoutControlItem
    Inherits LayoutItem
    Implements IContextItemCollectionOptionsOwner,
               IContextItemCollectionOwner

Remarks

A LayoutControlItem object can display an external control and a text description next to the control. The item's control is specified by the LayoutControlItem.Control property, the text description is specified by the BaseLayoutItem.Text property. The item's text can be hidden by setting the BaseLayoutItem.TextVisible property to false.

LayoutControlItem_structure

A layout item can be created as follows:

When a control is assigned to the LayoutControlItem.Control property, it is automatically added to the LayoutControl.Controls collection. After a control has been assigned to the LayoutControlItem.Control property, this property cannot be changed. Changing the bound control's properties that affect its visibility and position (for instance, Location, Parent, Size, Visible and Enabled) has no effect, use the properties provided by the LayoutControlItem class instead.

When an item is disposed of at runtime, its control is not destroyed.

NOTE

To allow a Layout Control's layout to be customized and serialized, you need to ensure that Name properties of the layout items and controls within the layout items are set to unique values. You must set the Name properties to unique values for layout items and controls that are created at runtime. The control's Name property must be initialized before this control is assigned to the LayoutControlItem.Control property.

Examples

The following example shows how to use the LayoutControl to create the following controls arrangement in Regular (default) layout mode (see LayoutGroup.LayoutMode).

CreateLayoutItems_ex

NOTE

To allow a LayoutControl'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.XtraEditors;
using DevExpress.XtraLayout;
using DevExpress.XtraLayout.Utils;

TextEdit editorName = new TextEdit() { Name = "editorName" };
MemoEdit editorAddress = new MemoEdit() { Name = "editorAddress" };
ButtonEdit editorEmail = new ButtonEdit() { Name = "editorEmail" };
PictureEdit editorPicture = new PictureEdit() { Name = "pePhoto" };
TextEdit editorPhone1 = new TextEdit() { Name = "editorPhone1" };
TextEdit editorPhone2 = new TextEdit() { Name = "editorPhone2" };
TextEdit editorFax = new TextEdit() { Name = "editorFax" };
SimpleButton btnOK = new SimpleButton() { Name = "btnOK", Text = "OK" };
SimpleButton btnCancel = new SimpleButton() { Name = "btnCancel", Text = "Cancel" };
MemoEdit editorNotes = new MemoEdit() { Name = "editorNotes" };

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

//Create a layout item in the Root group using the LayoutGroup.AddItem method
LayoutControlItem itemName = lc.Root.AddItem();
itemName.Name = "liName";
itemName.Control = editorName;
itemName.Text = "Name";

//Create a layout item using the LayoutControlItem constructor
LayoutControlItem itemAddress = new LayoutControlItem(lc, editorAddress);
itemAddress.Name = "liAddress";
itemAddress.Text = "Address";
// Move the layout item to a position next to the 'Name' layout item.
itemAddress.Move(itemName, InsertType.Right);

//Create a layout item using the LayoutControlItem constructor
LayoutControlItem itemEmail = new LayoutControlItem(lc, editorEmail);
itemEmail.Name = "liEmail";
itemEmail.Text = "E-mail";
// Move the layout item to a position below the 'Name' layout item.
itemEmail.Move(itemName, InsertType.Bottom);

// Add the Photo group.
LayoutControlGroup groupPhoto = lc.Root.AddGroup();
groupPhoto.Name = "lgPhoto";
groupPhoto.Text = "Photo";
// Add a new layout item to the group to display an image.
LayoutControlItem liPhoto = groupPhoto.AddItem();
liPhoto.Name = "liPhoto";
liPhoto.Control = editorPicture;
liPhoto.TextVisible = false;

//A tabbed group
TabbedControlGroup tabbedGroup = lc.Root.AddTabbedGroup(groupPhoto, InsertType.Right);
tabbedGroup.Name = "TabbedGroupPhoneFax";
// Add the Phone group as a tab.
LayoutControlGroup groupPhone = tabbedGroup.AddTabPage() as LayoutControlGroup;
groupPhone.Name = "lgPhone";
groupPhone.Text = "Phone";

LayoutControlItem liPhone1 = groupPhone.AddItem();
liPhone1.Name = "liPhone1";
liPhone1.Control = editorPhone1;
liPhone1.Text = "Phone 1";
LayoutControlItem liPhone2 = groupPhone.AddItem();
liPhone2.Name = "liPhone2";
liPhone2.Control = editorPhone2;
liPhone2.Text = "Phone 2";

// Add an empty resizable region below the last added layout item.
EmptySpaceItem emptySpace11 = new EmptySpaceItem();
emptySpace11.Parent = groupPhone;

// Add the Fax group as a tab.
LayoutControlGroup groupFax = tabbedGroup.AddTabPage() as LayoutControlGroup;
groupFax.Name = "lgFax";
groupFax.Text = "Fax";
LayoutControlItem liFax = groupFax.AddItem();
liFax.Name = "liFax";
liFax.Control = editorFax;
liFax.Text = "Fax";

// Add an empty resizable region below the last added layout item.
EmptySpaceItem emptySpace12 = new EmptySpaceItem();
emptySpace12.Parent = groupFax;

tabbedGroup.SelectedTabPage = groupPhone;

// Create a borderless group to display the OK and CANCEL buttons at the bottom of the LayoutControl
// If items are combined in a group, their alignmenent is not dependent on the items outside this group.
LayoutControlGroup groupButtons = lc.Root.AddGroup();
groupButtons.Name = "GroupButtons";
groupButtons.GroupBordersVisible = false;

EmptySpaceItem emptySpace2 = new EmptySpaceItem();
emptySpace2.Parent = groupButtons;

//Create a layout item (using the LayoutGroup.AddItem method) next to the 'emptySpace2' item
LayoutControlItem itemOKButton = groupButtons.AddItem(emptySpace2, InsertType.Right);
itemOKButton.Name = "liButtonOK";
itemOKButton.Control = btnOK;
itemOKButton.Text = "OK Button";
itemOKButton.TextVisible = false;
itemOKButton.SizeConstraintsType = SizeConstraintsType.Custom;
itemOKButton.MaxSize = new Size(200, 25);
itemOKButton.MinSize = new Size(90, 25);

//Create a layout item (using the LayoutGroup.AddItem method) next to the 'itemOKButton' item
LayoutControlItem itemCancelButton = groupButtons.AddItem(itemOKButton, InsertType.Right);
itemCancelButton.Name = "liButton";
itemCancelButton.Control = btnCancel;
itemCancelButton.Text = "Cancel Button";
itemCancelButton.TextVisible = false;
itemCancelButton.SizeConstraintsType = SizeConstraintsType.Custom;
itemCancelButton.MaxSize = new Size(200, 25);
itemCancelButton.MinSize = new Size(90, 25);

// Create a hidden layout item.
LayoutControlItem itemNotes = new LayoutControlItem();
itemNotes.Name = "liNotes";
lc.HiddenItems.AddRange(new BaseLayoutItem[] { itemNotes });
itemNotes.Control = editorNotes;
itemNotes.Text = "Notes";

Inheritance

See Also