本示例展示了如何使用一个 XtraTabbedMdiManager 组件在 MDI 应用程序中实现标签式界面。

当主窗体 (MDI 父窗体) 被加载时,通过设置 XtraTabbedMdiManager.MdiParent 属性,把一个 XtraTabbedMdiManager 对象绑定到此窗体。 另外,在主窗体顶部创建了一个工具栏,它包含一个 New 命令。 按下 New 命令将创建一个 MDI 子窗体,并且自动通过 XtraTabbedMdiManager 而把它显示为一个标签页。

创建两个子窗体的结果显示在下面:

C#CopyCode image复制代码
using System;
using System.Windows.Forms;
using DevExpress.XtraTabbedMdi;
using DevExpress.XtraBars;

namespace WindowsFormsApplication59 {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            // Create a BarManager that will display a bar of commands at the top of the main form.
            BarManager barManager = new BarManager();
            barManager.Form = this;
            // Create a bar with a New button.
            barManager.BeginUpdate();
            Bar bar = new Bar(barManager, "My Bar");
            bar.DockStyle = BarDockStyle.Top;
            barManager.MainMenu = bar;
            BarItem barItem = new BarButtonItem(barManager, "New");
            barItem.ItemClick += new ItemClickEventHandler(barItem_ItemClick);
            bar.ItemLinks.Add(barItem);
            barManager.EndUpdate();
            // Create an XtraTabbedMdiManager that will manage MDI child windows.
            XtraTabbedMdiManager mdiManager = new XtraTabbedMdiManager();
            mdiManager.MdiParent = this;
        }

        int ctr = 0;
        void barItem_ItemClick(object sender, ItemClickEventArgs e) {
            // Create an MDI child form.
            Form2 f = new Form2();
            f.Text = "Child Form " + (++ctr).ToString();
            f.MdiParent = this;
            f.Show();
        }
    }
}
Visual BasicCopyCode image复制代码
Imports DevExpress.XtraBars
Imports DevExpress.XtraTabbedMdi

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
        ' Create a BarManager that will display a bar of commands at the top of the main form.
        Dim barManager As BarManager = New BarManager()
        barManager.Form = Me
        ' Create a bar with a New button.
        barManager.BeginUpdate()
        Dim bar As Bar = New Bar(barManager, "My Bar")
        bar.DockStyle = BarDockStyle.Top
        barManager.MainMenu = bar
        Dim barItem As BarItem = New BarButtonItem(barManager, "New")
        AddHandler barItem.ItemClick, AddressOf barItem_ItemClick
        bar.ItemLinks.Add(barItem)
        barManager.EndUpdate()
        ' Create an XtraTabbedMdiManager that will manage MDI child windows.
        Dim mdiManager As XtraTabbedMdiManager = New XtraTabbedMdiManager()
        mdiManager.MdiParent = Me
    End Sub

    Private ctr As Integer = 0
    Private Sub barItem_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
        ' Create an MDI child form.
        Dim f As Form2 = New Form2()
        ctr = ctr + 1
        f.Text = "Child Form " & ctr.ToString()
        f.MdiParent = Me
        f.Show()
    End Sub
End Class