Solved

Resize and Minimize issue in vb.net

Posted on 2010-08-18
10
549 Views
Last Modified: 2012-05-10
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
Comment
Question by:RakeshBhandari
  • 4
  • 3
  • 3
10 Comments
 
LVL 4

Expert Comment

by:Sarika30
ID: 33463279
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
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 33463317
Do you want to keep only 1 form mazimized/restored inside your MDI parent while minimizing all the others?
0
 
LVL 4

Expert Comment

by:Sarika30
ID: 33463350
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
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 33463450
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
 
LVL 2

Author Comment

by:RakeshBhandari
ID: 33463702
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 25

Expert Comment

by:Luis Pérez
ID: 33463790
Why does it fails? Do you get an exception? Nothing happens? Where is executing those piece of code?
0
 
LVL 2

Author Comment

by:RakeshBhandari
ID: 33463830
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
 
LVL 4

Expert Comment

by:Sarika30
ID: 33463913
Have you tried this:

Dim frmChild As Form

For Each frmChild In Me.MdiChildren

    frmChild.WindowState = FormWindowState.Minimized
Next

0
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 125 total points
ID: 33463969
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
 
LVL 2

Author Closing Comment

by:RakeshBhandari
ID: 33464379
Good
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now