Winform+DevExpress多个子界面嵌入选项卡实例教程

1,XtraTabControl分页选项卡winform子窗体可以分两种情况展示在选项卡中;

具体以下图片展示:

        一;所有子窗体只在一个选项卡tab页中展示

Winform+DevExpress多个子界面嵌入选项卡实例教程_第1张图片

二;打开一个子窗体就相当于添加一个tab页

展示一下第一种样式的代码部分:

 private void LoadTabPageForm(XtraTabControl tabcontrol, Form form, String title)
        {
            bool found = false;
            XtraTabPage selectedPage = null;
            foreach (XtraTabPage page in tabcontrol.TabPages)
            {
                if (page.Tag != null && page.Text == title)
                {
                    found = true;
                    selectedPage = page;
                    break;
                }
            }
            if (!found)
            {
                selectedPage = new XtraTabPage();
                selectedPage.Text = title;
                selectedPage.Tag = form;
                form.TopLevel = false;
                form.Dock = DockStyle.Fill;
                form.FormBorderStyle = FormBorderStyle.None;
                form.Show();
                selectedPage.Controls.Clear();
                selectedPage.Controls.Add(form);

                if (!form.IsDisposed)
                {
                    tabcontrol.SelectedTabPage = selectedPage;
                    tabcontrol.TabPages.Add(selectedPage);   //把tabpage加入到tabcontrol里
                }
            }
            else
            {
                if (selectedPage.Tag != null && selectedPage.Tag != form)
                {
                    form.TopLevel = false;
                    form.Dock = DockStyle.Fill;
                    form.FormBorderStyle = FormBorderStyle.None;
                    form.Show();
                    selectedPage.Controls.Clear();
                    selectedPage.Controls.Add(form);
                }
            }
            selectedPage.BringToFront();
            tabcontrol.SelectedTabPage = selectedPage;
        }

页面关闭事件

  private void xTabPages_CloseButtonClick(object sender, EventArgs e)
        {
            XtraTabControl tabControl = sender as XtraTabControl;
            ClosePageButtonEventArgs arg = e as ClosePageButtonEventArgs;
            var page = arg.Page as XtraTabPage;
            if (page.HasChildren)
            {
                tabControl.TabPages.Remove(page);
                page.Controls.Clear();
                page.Dispose();
            }
        }

有疑问请留言 !!

你可能感兴趣的:(DevExpress,c#,开发语言)