Krunal Doshi

Hi,

I am building MDI application which has several child forms. I want to minimize my child forms to my MDI status bar using C#.Net (Same as all our open windows gets minimize in the windows task bar).

Can I do this How

Regards,

Krunal




Re: Windows Forms General Minimize MDI child forms

humble.apprentice

Hi Krunal,

Have you tried iterating through the MdiChildren collection You should have something like "this.MdiChildren". In your loop just set them to "Minimized". Hope this helps!

Cheers,






Re: Windows Forms General Minimize MDI child forms

Krunal Doshi

Hi,

No, this will not help me out to solve my problem. Actually I want that when user minimize any of my child form it should get minimize the same way when we minimize our application and it gets on the windows task bar.

- Krunal






Re: Windows Forms General Minimize MDI child forms

Chunsheng Tang - MSFT

Hi, Krunal

The build-in support for this is:

Code Block
foreach (Form frm in this.MdiChildren)
{
frm.WindowState = FormWindowState.Minimized;
}

Anything beyond it need you do some work. For example you can build a custom control that has the ability to manage child windows. Also maybe you need to build a framework for it just like Tabbed Windows.

Best Regards

Chunsheng Tang






Re: Windows Forms General Minimize MDI child forms

Sharad Nair

Hi Krunal,

If I understand your query correctly it can be split into two parts:


Firstly you would like to minimize all the child windows on your MDI Parent for which you can use the solution provided by

Chunsheng Tang or humble.apprentice above.


I will try to answer the second part of your question i.e on how to create the effect of minimizing the windows to the MDI's

status bar as minimized windows appear on the windows task bar. .Net does not provide this feature by default and will

require you to do some coding for the same. Here's what I can suggest:

1) Drag and drop a StatusStrip control on your MDI parent window. This is the control which will hold your minimized windows (or atleast create the effect of holding the windows).

2) Create a public function in the MDI window class as follows:

public void MinimizeWindowsOnStausBar(Form childForm)
{
//create an instance of a ToolStripButton which will give the effect of a window minimized in the StatusBar.
ToolStripButton tsb = new ToolStripButton(childForm.Text);

//use the Tag property of the ToolStripButton to hold the reference to the child window which is being minimized
//as this reference will be used later to maximize the window when clicked in the status bar.
tsb.Tag = childForm;

//optionally set the backcolor of the ToolStripButton to give it the look and feel of the XP theme
tsb.BackColor = Color.Blue;

//assign an event handler for the button. The event handler provided here will be called when the user will click
//the window name in the status bar.
tsb.Click += new EventHandler(tsb_Click);

//hide the form that is being minimized.
childForm.Visible = false;

//add the newly created button to the Status Strip control added to the MDI Parent in step 1 above.
statusStrip1.Items.Add(tsb);
}


//event handler function that will handle the tsb.Click event as assigned above.
void tsb_Click(object sender, EventArgs e)
{
ToolStripButton tsb;

//Typecast the sender object to ToolStripButton as the sender is always going to be a ToolStripButton.
tsb = (ToolStripButton)sender;

Form childForm;


//retrieve the chilform object from the Tag property of the ToolStripButton. This Tag property was initialized in
//the MinimizeWindowsOnStausBar function.
childForm = (Form)tsb.Tag;
childForm.WindowState = FormWindowState.Normal;


//make the window visible.
childForm.Visible = true;

//remove the button representing the minimized window as the window is no longer minimized.
statusStrip1.Items.Remove(tsb);
}

3) Now we need to make calls to the MinimizeWindowsOnStausBar function whenever a child window is minimized. For this I have placed code in the Resize event handler of each of the child forms. I am sure you can optimize it further by using a more generic approach. But for now you can place the following code in the Resize event handler of each of the Child forms.

private void Child1_Resize(object sender, EventArgs e)
{
//check if the child form has been resized and is visible so that the code only executes when the child form is
//being minimized.
if (this.WindowState == FormWindowState.Minimized && this.Visible)
{
//Form1 is the MDI Parent form. You should replace this with the name of your MDI Parent form.
Form1 frmMain;


//typecast the MDIParent of the child form that is being minimized so that we can call the
//MinimizeWindowsOnStausBar function on the MDI Parent.
frmMain = (Form1)this.MdiParent;


//Call the MinimizeWindowsOnStausBar function which will create the effect of window being minimized onto the
//status bar.
frmMain.MinimizeWindowsOnStausBar(this);
}
}


This is a very quick solution to your problem and I would recommend you to optimize or modify the code as per your need. I hope this solution would be of some help to you.

Cheers
Sharad






Re: Windows Forms General Minimize MDI child forms

Krunal Doshi

Although I have to modify as per my requirements, but thanks for your ideas.

Thank you Sharad

-Krunal






Re: Windows Forms General Minimize MDI child forms

syedumarali

Hi Sharad Nair,

First of all i want to tell that i am a bgnr for this course plz tell me how many forms i can take and whr can i place 2 and 3 points of code in my form and what are the form names that i can modify.

i am looking for ur reply

Thanks bye...





Re: Windows Forms General Minimize MDI child forms

Sharad Nair

Hi Syedumarali,

Sorry for the delayed response, but I was not around for a while.

the code snippet in point 2. should be placed in the MDI form class and point no. 3 should be placed in the resize event handler of every child form that you like to add the functionality to.

Moreover you must replace statusStrip1 with the actual name of the Status Strip control that you would place on the MDI form.

You would also need to change line no.8 in the code snippet provided in point 3. i.e. you would have to replace

Form1 in "Form1 frmMain" to the actual name of the MDI form that you would create. You don't have to make any other modifications and the code will work for you.

Hope i have explained what you were looking for.

cheers

Sharad






Re: Windows Forms General Minimize MDI child forms

syedumarali

hi,

same problem for me also

how can i do this plz help me





Re: Windows Forms General Minimize MDI child forms

Sharad Nair

Hi Syedumarali,

Anything specific that you would like to ask

cheers
Sharad