Link to home
Start Free TrialLog in
Avatar of RakeshBhandari
RakeshBhandariFlag for India

asked on

Resize and Minimize issue in vb.net

I developing windows application in VB.net using c# for coding  in vs2008. In my application i using MDI form inside that many child forms.  Form1  is opened in my application and it minimizing when i  opening Form2. My problem is when i maximize(restore)  From1 , Form2 should minimize,  how where should write code?.

  i giving here my code for minimize window

  Form[] charr = this.MdiChildren;
            foreach (Form chform in charr)
                chform.WindowState = FormWindowState.Minimized;
Avatar of Sarika30
Sarika30
Flag of India image

You should write the code to minimize other forms on the form resize event of form1.

private void Form1_Resize(object sender, EventArgs e)
        {

        }
Avatar of Luis Pérez
Do you want to keep only 1 form mazimized/restored inside your MDI parent while minimizing all the others?
To minimize all forms, use :
For Each form As Form In Me.MdiChildren
 form.WindowState = FormWindowState.Minimized
 Next

To Minimize only one form, use:
Form2.ActiveForm.WindowState = FormWindowState.Minimized;
You can accomplish the task in the MdiChildActivate event of the MDI parent form. Check the attached code.

Hope that helps.
if ((this.ActiveMdiChild != null)) {
	foreach (Form children in this.MdiChildren) {
		if (!(object.ReferenceEquals(children, this.ActiveMdiChild))) {
			children.WindowState = FormWindowState.Minimized;
		}
	}
}

Open in new window

Avatar of RakeshBhandari

ASKER

I did that each forms but this not working my code is

Form[] charr = this.MdiChildren;
            foreach (Form chform in charr)
                chform.WindowState = FormWindowState.Minimized;
Why does it fails? Do you get an exception? Nothing happens? Where is executing those piece of code?
i not geting any exceptions.  i wrote this each child forms   resize event. but this not working
 here my code

  private void AddUser_Resize(object sender, EventArgs e)
        {
            Form[] charr = this.MdiChildren;
            foreach (Form chform in charr)
                chform.WindowState = FormWindowState.Minimized;
        }
Have you tried this:

Dim frmChild As Form

For Each frmChild In Me.MdiChildren

    frmChild.WindowState = FormWindowState.Minimized
Next

ASKER CERTIFIED SOLUTION
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good