Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


C#
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;
            }
        }


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

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



C#
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????
Posted

sorry for belated reply.

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

how can i avoid this
 
Share this answer
 
Comments
CHill60 22-Jun-13 8:15am    
Try to avoid adding solutions to your own posts - not many people will notice them. If you want to add something to your question use the "Improve question" link (in green below your question), or if you want to respond to a Solution use the "Have a Question or Comment?" link (in cream below the relevant solution). Finally, if you want to respond to a comment (like this one) then use the "Reply" link (to the right of the relevant comment).
I hope this helps you to get more out of CodeProject :-)
Balasubramanian T 22-Jun-13 8:41am    
thank u brother...can u help this problem
this.ActiveMdiChild.Tag takes onle null value
any other mistakes?
plz notify me.as soon as possible
CHill60 22-Jun-13 10:12am    
Where do you create the child forms - in code or at design time? You may not have an active child form at all.
Balasubramanian T 23-Jun-13 9:27am    
design only...
CHill60 23-Jun-13 9:59am    
You'll need to show/activate a child form e.g. in Main_Load or from a menu on the MDI form have something like <pre> f2 = new Form2();
f2.MdiParent = this;
f2.Show();</pre> Your Main_MdiChildActivate will get fired and this.ActiveMdiChild should be a reference to the form just shown
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900