Windows Develop Bookmark and Share   
 index > Windows Forms Designer > displaying multiple forms in mdi
 

displaying multiple forms in mdi

Hi, I have seen in the forums here that when your using mdi app you cant show individual forms (when open) on the taskbar. Thats fair enough my question would be is there a way to show forms perhaps on the status bar or something like the windowsmenu but showing on the bottom of the mdiparent form?
intozz  Wednesday, March 11, 2009 12:33 AM

Hi intozz,

I can just simulate this effect, it works not perfect enough. Here is my code.
FrmMain: MDI parent Form

publicpartialclassFrmMain:Form
{
publicFrmMain()
{
InitializeComponent();
this.statusStrip1.ItemClicked+=newToolStripItemClickedEventHandler(statusStrip1_ItemClicked);
}
voidstatusStrip1_ItemClicked(objectsender,ToolStripItemClickedEventArgse)
{
ToolStripButtontsButton=e.ClickedItemasToolStripButton;
if(tsButton!=null)
{
foreach(FormmdiChildinthis.MdiChildren)
{
if(mdiChild.Name==tsButton.Name)
{
mdiChild.WindowState=FormWindowState.Normal;
mdiChild.Visible=true;
}
}
}
}
privatevoidform1ToolStripMenuItem_Click(objectsender,EventArgse)
{
Form1form1=newForm1();
form1.MdiParent=this;
form1.StatusStrip=this.statusStrip1;
form1.Show();
}
privatevoidform2ToolStripMenuItem_Click(objectsender,EventArgse)
{
Form2form2=newForm2();
form2.MdiParent=this;
form2.StatusStrip=this.statusStrip1;
form2.Show();
}
}


In parent form, I drag a statusStrip to it(named statusStrip1). When I create child form, I will transmit statusStrip1 to the child form so the child form can add a button on it.

Form1: one of its child form

publicpartialclassForm1:Form
{
privateStatusStripstatusStrip;
publicStatusStripStatusStrip
{
get{returnstatusStrip;}
set{statusStrip=value;}
}
privateToolStripButtontsButton;
publicForm1()
{
InitializeComponent();
}
privatevoidForm1_Load(objectsender,EventArgse)
{
tsButton=newToolStripButton(this.Name);
tsButton.Name=this.Name;
statusStrip.Items.Add(tsButton);
this.FormClosing+=newFormClosingEventHandler(Form1_FormClosing);
this.SizeChanged+=newEventHandler(Form1_SizeChanged);
}
voidForm1_FormClosing(objectsender,FormClosingEventArgse)
{
statusStrip.Items.Remove(tsButton);
}
voidForm1_SizeChanged(objectsender,EventArgse)
{
if(this.WindowState==FormWindowState.Minimized)
{
this.Visible=false;
}
}
}


In each child form, there is an StatusStrip which hold the StatusStrip of parent form.

When the form is load, it will create a ToolStripButton to the StatusStrip.
When the form is closed, it will remove the button.
When the form is minimized, it will hide itself.

When the ToolStripButton in the StatusStrip of parent form is clicked, it should show child form.

Form2's code is similar to Form1:

publicpartialclassForm2:Form
{
privateStatusStripstatusStrip;
privateToolStripButtontsButton;
publicStatusStripStatusStrip
{
get{returnstatusStrip;}
set{statusStrip=value;}
}
publicForm2()
{
InitializeComponent();
}
privatevoidForm2_Load(objectsender,EventArgse)
{
tsButton=newToolStripButton(this.Name);
tsButton.Name=this.Name;
statusStrip.Items.Add(tsButton);
this.FormClosing+=newFormClosingEventHandler(Form2_FormClosing);
this.SizeChanged+=newEventHandler(Form2_SizeChanged);
}
voidForm2_FormClosing(objectsender,FormClosingEventArgse)
{
statusStrip.Items.Remove(tsButton);
}
voidForm2_SizeChanged(objectsender,EventArgse)
{
if(this.WindowState==FormWindowState.Minimized)
{
this.Visible=false;
}
}
}

You can download the whole sample from my SkyDrive.(Made in VS 2008 C#)
http://cid-380a93ce0876cf8b.skydrive.live.com/self.aspx/Microsoft%20MSDN%20Work/Solution%20Code/MDISubFormInBar.rar

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Thursday, March 12, 2009 9:02 AM

Hi intozz,

I can just simulate this effect, it works not perfect enough. Here is my code.
FrmMain: MDI parent Form

publicpartialclassFrmMain:Form
{
publicFrmMain()
{
InitializeComponent();
this.statusStrip1.ItemClicked+=newToolStripItemClickedEventHandler(statusStrip1_ItemClicked);
}
voidstatusStrip1_ItemClicked(objectsender,ToolStripItemClickedEventArgse)
{
ToolStripButtontsButton=e.ClickedItemasToolStripButton;
if(tsButton!=null)
{
foreach(FormmdiChildinthis.MdiChildren)
{
if(mdiChild.Name==tsButton.Name)
{
mdiChild.WindowState=FormWindowState.Normal;
mdiChild.Visible=true;
}
}
}
}
privatevoidform1ToolStripMenuItem_Click(objectsender,EventArgse)
{
Form1form1=newForm1();
form1.MdiParent=this;
form1.StatusStrip=this.statusStrip1;
form1.Show();
}
privatevoidform2ToolStripMenuItem_Click(objectsender,EventArgse)
{
Form2form2=newForm2();
form2.MdiParent=this;
form2.StatusStrip=this.statusStrip1;
form2.Show();
}
}


In parent form, I drag a statusStrip to it(named statusStrip1). When I create child form, I will transmit statusStrip1 to the child form so the child form can add a button on it.

Form1: one of its child form

publicpartialclassForm1:Form
{
privateStatusStripstatusStrip;
publicStatusStripStatusStrip
{
get{returnstatusStrip;}
set{statusStrip=value;}
}
privateToolStripButtontsButton;
publicForm1()
{
InitializeComponent();
}
privatevoidForm1_Load(objectsender,EventArgse)
{
tsButton=newToolStripButton(this.Name);
tsButton.Name=this.Name;
statusStrip.Items.Add(tsButton);
this.FormClosing+=newFormClosingEventHandler(Form1_FormClosing);
this.SizeChanged+=newEventHandler(Form1_SizeChanged);
}
voidForm1_FormClosing(objectsender,FormClosingEventArgse)
{
statusStrip.Items.Remove(tsButton);
}
voidForm1_SizeChanged(objectsender,EventArgse)
{
if(this.WindowState==FormWindowState.Minimized)
{
this.Visible=false;
}
}
}


In each child form, there is an StatusStrip which hold the StatusStrip of parent form.

When the form is load, it will create a ToolStripButton to the StatusStrip.
When the form is closed, it will remove the button.
When the form is minimized, it will hide itself.

When the ToolStripButton in the StatusStrip of parent form is clicked, it should show child form.

Form2's code is similar to Form1:

publicpartialclassForm2:Form
{
privateStatusStripstatusStrip;
privateToolStripButtontsButton;
publicStatusStripStatusStrip
{
get{returnstatusStrip;}
set{statusStrip=value;}
}
publicForm2()
{
InitializeComponent();
}
privatevoidForm2_Load(objectsender,EventArgse)
{
tsButton=newToolStripButton(this.Name);
tsButton.Name=this.Name;
statusStrip.Items.Add(tsButton);
this.FormClosing+=newFormClosingEventHandler(Form2_FormClosing);
this.SizeChanged+=newEventHandler(Form2_SizeChanged);
}
voidForm2_FormClosing(objectsender,FormClosingEventArgse)
{
statusStrip.Items.Remove(tsButton);
}
voidForm2_SizeChanged(objectsender,EventArgse)
{
if(this.WindowState==FormWindowState.Minimized)
{
this.Visible=false;
}
}
}

You can download the whole sample from my SkyDrive.(Made in VS 2008 C#)
http://cid-380a93ce0876cf8b.skydrive.live.com/self.aspx/Microsoft%20MSDN%20Work/Solution%20Code/MDISubFormInBar.rar

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Thursday, March 12, 2009 9:02 AM
hi there, firstly im working in vb. so heres my converted code:-

'mdiparent'

Inherits Form
Public Sub New()
InitializeComponent()
AddHandler Me.StatusStrip1.ItemClicked, AddressOf statusStrip1_ItemClicked
End Sub

Private Sub statusStrip1_ItemClicked(ByVal sender As Object, ByVal e As ToolStripItemClickedEventArgs)
Dim tsButton As ToolStripButton = TryCast(e.ClickedItem, ToolStripButton)
If tsButton IsNot Nothing Then
For Each mdiChild As Form In Me.MdiChildren
If mdiChild.Name = tsButton.Name Then
mdiChild.WindowState = FormWindowState.Normal
mdiChild.Visible = True
End If
Next
End If
End Sub

Private Sub workscheduleentryToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim workscheduleentry As New WORKSCHEDULEENTRY()
workscheduleentry.MdiParent = Me
workscheduleentry.StatusStrip = Me.StatusStrip1
workscheduleentry.Show()
End Sub


'form1'

Inherits Form
Private m_statusStrip As StatusStrip
Public Property StatusStrip() As StatusStrip
Get
Return m_statusStrip
End Get
Set(ByVal value As StatusStrip)
m_statusStrip = value
End Set
End Property

Private tsButton As ToolStripButton

Private Sub StatusStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles StatusStrip1.ItemClicked

End Sub
Public Sub New()
InitializeComponent()
End Sub

Private Sub workscheduleentry_Load(ByVal sender As Object, ByVal e As EventArgs)
tsButton = New ToolStripButton(Me.Name)
tsButton.Name = Me.Name
m_statusStrip.Items.Add(tsButton)
AddHandler Me.FormClosing, AddressOf workscheduleentry_FormClosing
AddHandler Me.SizeChanged, AddressOf workscheduleentry_SizeChanged


no errors happen when i run this and everything loads and still works but i dont get anything on my statustrip. Should I also have a status strip drag on my 'form1' that the mdi merges with?
intozz  Thursday, March 12, 2009 10:51 PM

Hi intozz,

No, you only need to drag a StatusStrip to your MDI parent form(FrmMain). In Form1, it will add a button to the StatusStrip of parent form.

You can download the whole project from my SkyDrive, through it is made in C#, But you can see the whole design form and run it to see the effect.

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Friday, March 13, 2009 2:12 AM

You can use google to search for other answers

Custom Search

More Threads

• GroupBox in a UserControl, redux
• Controls, Particularly User Controls, disappearing or Being Resized on Build
• number lines of code
• more than one value in listbox
• Property value stored in the Resx (string table) when edited in the forms designer
• form position on runtime
• Custom Form Designer class issue
• How to assign string resource to user control's property at design time?
• How to make the buttons round in the VS 2008
• Wepos 1.1 Image and registry key