Back to Devexpress

How to: Create a tabbed group in code

windowsforms-2253-controls-and-libraries-form-layout-managers-layout-and-data-layout-controls-examples-how-to-create-a-tabbed-group-in-code.md

latest3.9 KB
Original Source

How to: Create a tabbed group in code

  • Nov 13, 2018
  • 3 minutes to read

The following example shows how to create a tabbed group that contains two pages. The first page will display a group with a layout item that contains a PictureEdit editor.

A tabbed group is created using the LayoutControlGroup.AddTabbedGroup method of the root group. Tabs are added via the TabbedGroup.AddTabPage method.

The following image shows the result:

csharp
using DevExpress.XtraLayout;

LayoutControl lc = new LayoutControl();
lc.Dock = System.Windows.Forms.DockStyle.Fill;
this.Controls.Add(lc);
// Lock the layout control to prevent excessive updates.
lc.BeginUpdate();
try {
    // Create a tabbed group within the root group.
    TabbedControlGroup tabbedGroup = lc.Root.AddTabbedGroup();
    tabbedGroup.Name = "TabbedGroup";
    // Add the Photo group as a tab.
    LayoutControlGroup groupPhoto = tabbedGroup.AddTabPage() as LayoutControlGroup;
    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 = new DevExpress.XtraEditors.PictureEdit() { Name = "pePhoto" };
    // Hide the item's text region.
    liPhoto.TextVisible = false;
    // Add the Notes group as a tab.
    LayoutControlGroup groupNotes = tabbedGroup.AddTabPage() as LayoutControlGroup;
    groupNotes.Name = "lgNotes";
    groupNotes.Text = "Notes";
    // Add a new layout item to the group to display a memo editor.
    LayoutControlItem liNotes = groupNotes.AddItem();
    liNotes.Name = "liNotes";
    liNotes.Control = new DevExpress.XtraEditors.MemoEdit() { Name = "meNotes" }; ;
    // Hide the item's text region.
    liNotes.TextVisible = false;

    // Make the first tab page active.
    tabbedGroup.SelectedTabPage = groupPhoto;
}
finally {
    // Unlock and update the layout control.
    lc.EndUpdate();
}
vb
Imports DevExpress.XtraLayout

    Dim lc As New LayoutControl()
    lc.Dock = System.Windows.Forms.DockStyle.Fill
    Me.Controls.Add(lc)
    ' Lock the layout control to prevent excessive updates.
    lc.BeginUpdate()
    Try
        ' Create a tabbed group within the root group.
        Dim tabbedGroup As TabbedControlGroup = lc.Root.AddTabbedGroup()
        tabbedGroup.Name = "TabbedGroup"
        ' Add the Photo group as a tab.
        Dim groupPhoto As LayoutControlGroup = TryCast(tabbedGroup.AddTabPage(), LayoutControlGroup)
        groupPhoto.Name = "lgPhoto"
        groupPhoto.Text = "Photo"
        ' Add a new layout item to the group to display an image.
        Dim liPhoto As LayoutControlItem = groupPhoto.AddItem()
        liPhoto.Name = "liPhoto"
        liPhoto.Control = New DevExpress.XtraEditors.PictureEdit() With { _
            Key .Name = "pePhoto" _
        }
        ' Hide the item's text region.
        liPhoto.TextVisible = False
        ' Add the Notes group as a tab.
        Dim groupNotes As LayoutControlGroup = TryCast(tabbedGroup.AddTabPage(), LayoutControlGroup)
        groupNotes.Name = "lgNotes"
        groupNotes.Text = "Notes"
        ' Add a new layout item to the group to display a memo editor.
        Dim liNotes As LayoutControlItem = groupNotes.AddItem()
        liNotes.Name = "liNotes"
        liNotes.Control = New DevExpress.XtraEditors.MemoEdit() With { _
            Key .Name = "meNotes" _
        }
        ' Hide the item's text region.
        liNotes.TextVisible = False

        ' Make the first tab page active.
        tabbedGroup.SelectedTabPage = groupPhoto
    Finally
        ' Unlock and update the layout control.
        lc.EndUpdate()
    End Try