如何避免子MDI选项卡控件中的重复选项卡 [英] How to Avoid Duplicate tabs in child MDI Tab Control

查看:71
本文介绍了如何避免子MDI选项卡控件中的重复选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经完成了一个由.NET Window应用程序和c#完成的项目。现在我在tabbed mdi Child控件中的问题(我从选项卡式MDI子窗体下载[ ^ ])。如果我打开表单,它将成功打开。如果我再次打开相同的表格,它会打开。这意味着重复选项卡。





Hi to everyone,
I have completed one project for Hotel by .NET Window applications and c#. now my problem in tabbed mdi Child control(which i download from Tabbed MDI Child Forms[^]). if i open a form, it will open successfully. if i open same form again it opens. that means duplication of tabs.


private void Main_MdiChildActivate(object sender, EventArgs e)
        {
            if (this.ActiveMdiChild == null)
                tabForms.Visible = false; // If no any child form, hide tabControl
            else
            {
                this.ActiveMdiChild.WindowState = FormWindowState.Maximized; // Child form always maximized

                // If child form is new and no has tabPage, create new tabPage
                if (this.ActiveMdiChild.Tag == null)
                {
                    // Add a tabPage to tabControl with child form caption
                    TabPage tp = new TabPage(this.ActiveMdiChild.Text);
                    tp.Tag = this.ActiveMdiChild;
                    tp.Parent = tabForms;
                    tabForms.SelectedTab = tp;

                    this.ActiveMdiChild.Tag = tp;
                    this.ActiveMdiChild.FormClosed += new FormClosedEventHandler(ActiveMdiChild_FormClosed);
                }

                if (!tabForms.Visible) tabForms.Visible = true;
            }
        }







private void ActiveMdiChild_FormClosed(object sender, FormClosedEventArgs e)
       {
           ((sender as Form).Tag as TabPage).Dispose();

           if (!tabForms.HasChildren)
               tabForms.Visible = false;
       }










private void tabForms_SelectedIndexChanged_1(object sender, EventArgs e)
{
    if ((tabForms.SelectedTab != null) && (tabForms.SelectedTab.Tag != null))
        (tabForms.SelectedTab.Tag as Form).Select();
}





任何人都可以帮助我????



can anyone help me????

推荐答案

抱歉迟来的回复。



每次this.ActiveMdiChild.Tag取值为null



我怎么能避免这个
sorry for belated reply.

every time this.ActiveMdiChild.Tag takes the value of null

how can i avoid this


请参考SA在这篇文章中的回复具有不同表单标题的MdiChild [ ^ ] - 忽略问题标题,只看SA的评论和链接。

我先指导你,因为他有效有关MDI表单的评论。



您可能还想查看此代码项目文章 MDI子表单的单例模式 [ ^ ]



几天前在codeproject中有一个类似的问题,所以在这个网站内搜索MDI也可能会给你一些其他有用的提示
Please refer to SA's response at this post MdiChild with different form title[^] - ignore the question title, just look at SA's comments and links.
I'm directing you there first as he has valid comments regarding MDI forms.

You might also want to look at this codeproject article Singleton pattern for MDI child forms[^]

There was a similar question here in codeproject a couple of days ago, so searching for MDI just within this site might also give you some other useful hints


这篇关于如何避免子MDI选项卡控件中的重复选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆