Click here to Skip to main content
15,913,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to minimize all child processes windows from c# code

Application.openforms return 0 length.


Thanks in advanced

What I have tried:

foreach (Form f in Application.OpenForms)
              {

                      f.WindowState = FormWindowState.Minimized;

              }
Posted
Updated 16-Jun-19 21:46pm

Normally, a Application.OpenForms Property (System.Windows.Forms) | Microsoft Docs[^] should do the job, but...

The reason of such of behaviour has been described here: c# - Application.OpenForms.Count = 0 always - Stack Overflow[^]
 
Share this answer
 
Comments
BillWoodruff 18-Jun-19 15:34pm    
+5 very interesting thread on SO
Maciej Los 19-Jun-19 1:51am    
Thank you, Bill.
The code works fine for me, which is exactly what I'd expect.

So you need to do a couple of things:
1) Check when you are executing that code: if it's from a constructor, the forms you want may not be fully initialized yet for example.
2) Check your UIPermission:
Quote:
Caller must have permission to access all windows, as defined by the AllWindows value of the UIPermissionWindow enumeration.
(Application.OpenForms Property (System.Windows.Forms) | Microsoft Docs[^])
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900