How to minimize all active forms in my application using VB.NET?

How to minimize all active forms in the application with the click of a button?

I have several forms visible at a time, and I want all my active forms to collapse when I click one button on one of the forms.

How can i achieve this?

+3
source share
2 answers

If you are not trying to minimize MDI child windows, you can simply view all open forms in your application and set their Minimize WindowStateproperty . VB.NET provides OpenFormsfor yours Application, which makes it speculatively simple.

Click :

For Each frm As Form in Application.OpenForms
    frm.WindowState = FormWindowState.Minimized
Next frm


, " " , . , OnSizeChanged , .

, , . , , "" "".

, :

Protected Overrides Sub OnSizeChanged(ByVal e As System.EventArgs)
    ' Call the base class first
    MyBase.OnSizeChanged(e)

    ' See if this form was just minimized
    If Me.WindowState = FormWindowState.Minimized Then
        ' Minimize all open forms
        For Each frm As Form In Application.OpenForms
            frm.WindowState = FormWindowState.Minimized
        Next frm
    ElseIf Me.WindowState = FormWindowState.Normal Then
        ' Restore all open forms
        For Each frm As Form In Application.OpenForms
            frm.WindowState = FormWindowState.Normal
        Next frm
    End If
End Sub
+7

Application.Forms.

For Each form as Form in Application.OpenForms
     .....
End For

?

+3

Source: https://habr.com/ru/post/1794044/


All Articles