minimize all active forms in my application

AMER SAID 396 Reputation points
2023-05-04T17:04:54.6966667+00:00

HI

I want to minimize all open windows active in the application together and restore them together when clicking on them on the taskbar.

Form open is CenterParent .

code not work to minimize all and restore all open


        foreach (Form form in Application.OpenForms)
                if (form.IsMdiChild)
                    form.WindowState = FormWindowState.Minimized;
       

Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Minxin Yu 13,506 Reputation points Microsoft External Staff
    2023-05-08T06:51:40.5333333+00:00

    Hi,

    ShowDialog can not work with FormWindowState.Minimized. It is by design. Consider using Show(this) and

    foreach (Form form in Application.OpenForms){
     form.WindowState = FormWindowState.Minimized;
    }
    
    

    For your reference: Why does modal-form disappear completely when minimized?

    When the user minimizes the dialog window, there are no windows left that the user can access. Making the app unusable. Winforms ensures this cannot happen by automatically closing the dialog when it gets minimized.

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.