![]() |
Languages »
C# »
Windows Forms
Advanced
Tabbed MDI Child FormsBy Serdar YILMAZAn article about browsing MDI child forms on tab page |
C#, Windows, .NET, Visual Studio, WinForms, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||

MDI child forms on tab page like Internet Explorer 7. So easy to use and a little code necessary.
First, set isMDIContainer property of the parent
form to true. Add a TabControl
component to the main form and set the Dock property
to Top. Delete all tab pages of TabControl and
set the Name property to
tabForms and set the Visible property to false.
No any code necessary for child forms. All codes in main forms.
When the MDI Child Form is activated; if child form has a tab page, activate the corresponding tab page else create a tab page for child form and select tab page.
private void Form1_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;
}
}
When the MDI Child Form is closing, destroy the corresponding tab page. Add the following code to main form.
private void ActiveMdiChild_FormClosed(object sender,
FormClosedEventArgs e)
{
((sender as Form).Tag as TabPage).Dispose();
}
When a tab page selected, activate its child form
private void tabForms_SelectedIndexChanged(object sender,
EventArgs e)
{
if ((tabForms.SelectedTab != null) &&
(tabForms.SelectedTab.Tag != null))
(tabForms.SelectedTab.Tag as Form).Select();
}
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 13 Feb 2007 Editor: Paul Conrad |
Copyright 2007 by Serdar YILMAZ Everything else Copyright © CodeProject, 1999-2009 Web10 | Advertise on the Code Project |