How I will Convert this into class which minimize all the childform? When I try to transfer it into class I got error :
The type or namespace name 'MdiChildren' could not be found (are you missing a using directive or an assembly reference?)
public void minimizeAll()
{
foreach (Form childForm in MdiChildren)
{
childForm.WindowState = FormWindowState.Minimized;
}
}
MdiChildren is not a static property, you need to use an instance of a form. You could pass in a Form as a parameter.
public void minimizeAll(Form parentForm)
{
foreach (Form childForm in parentForm.MdiChildren)
{
childForm.WindowState = FormWindowState.Minimized;
}
}
You may try using something like this (hardly you have many MDI parent forms):
public static class Minimizer {
public static void MinimizeMdiChildren() {
// Enumerate all forms, minimize MDI Children
foreach (Form form in Application.OpenForms)
if (form.IsMdiChild)
form.WindowState = FormWindowState.Minimized;
}
}
...
Minimizer.MinimizeMdiChildren();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With