Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 570
  • Last Modified:

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;
0
RakeshBhandari
Asked:
RakeshBhandari
  • 4
  • 3
  • 3
1 Solution
 
Sarika30Commented:
You should write the code to minimize other forms on the form resize event of form1.

private void Form1_Resize(object sender, EventArgs e)
        {

        }
0
 
Luis PérezSoftware Architect in .NetCommented:
Do you want to keep only 1 form mazimized/restored inside your MDI parent while minimizing all the others?
0
 
Sarika30Commented:
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;
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Luis PérezSoftware Architect in .NetCommented:
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

0
 
RakeshBhandariAuthor Commented:
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;
0
 
Luis PérezSoftware Architect in .NetCommented:
Why does it fails? Do you get an exception? Nothing happens? Where is executing those piece of code?
0
 
RakeshBhandariAuthor Commented:
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;
        }
0
 
Sarika30Commented:
Have you tried this:

Dim frmChild As Form

For Each frmChild In Me.MdiChildren

    frmChild.WindowState = FormWindowState.Minimized
Next

0
 
Luis PérezSoftware Architect in .NetCommented:
You are wrong in placing your code inside Resize event of each child form. If you look at your code:

Form[] charr = this.MdiChildren;
foreach (Form chform in charr)
chform.WindowState = FormWindowState.Minimized;

But "this.MdiChildren" inside a child form will be empty!! Because the child form has no any children.

Try my code posted above (I repeat it here), but place the code into the MdiChildActivate event of the MDI parent form.

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

0
 
RakeshBhandariAuthor Commented:
Good
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now