A LayoutControlItem object can display an external control and a text description next to the control. The item's control is specified by the 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.
A layout item can be created as follows:
When a control is assigned to the Control property, it is automatically added to the LayoutControl.Controls collection. After a control has been assigned to the 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 Control property.
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.
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 Control property.
C# |
using DevExpress.XtraLayout;
using DevExpress.XtraEditors;
LayoutControl lc = new LayoutControl();
lc.Dock = System.Windows.Forms.DockStyle.Fill;
this.Controls.Add(lc);
LayoutControlItem item1 = lc.Root.AddItem();
item1.Name = "Layout Item 1";
Control textBox1 = new TextEdit();
textBox1.Name = "TextBox1";
item1.Control = textBox1;
item1.Text = "Name";
LayoutControlItem item2 = new LayoutControlItem();
item2.Parent = lc.Root;
item2.Name = "Layout Item 2";
Control textBox2 = new TextEdit();
textBox2.Name = "TextBox2";
item2.Control = textBox2;
item2.Text = "E-mail";
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";
|
VB |
Imports DevExpress.XtraLayout
Imports DevExpress.XtraEditors
Dim lc As New LayoutControl()
lc.Dock = System.Windows.Forms.DockStyle.Fill
Me.Controls.Add(lc)
Dim item1 As LayoutControlItem = lc.Root.AddItem()
item1.Name = "Layout Item 1"
Dim textBox1 As Control = New TextEdit()
textBox1.Name = "TextBox1"
item1.Control = textBox1
item1.Text = "Name"
Dim item2 As New LayoutControlItem()
item2.Parent = lc.Root
item2.Name = "Layout Item 2"
Dim textBox2 As Control = New TextEdit()
textBox2.Name = "TextBox2"
item2.Control = textBox2
item2.Text = "E-mail"
Dim item3 As New LayoutControlItem()
item3.Name = "Layout Item 3"
lc.HiddenItems.AddRange(New BaseLayoutItem() {item3})
Dim textBox3 As Control = New MemoEdit()
textBox3.Name = "TextBox3"
item3.Control = textBox3
item3.Text = "Notes"
|
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
DevExpress.XtraLayout.SupportVisitor
BaseLayoutItem
LayoutItem
LayoutControlItem
EmptySpaceItem
LayoutRepositoryItem
LayoutViewField
SplitterItem