WindowState Property Example

This example hides a dialog box (Form2) when the parent form (Form1) is minimized and redisplays the dialog box when the parent form is returned to either an original or maximized state. To try this example, paste the code into the Declarations section of Form1 of an application that contains two forms. Press F5 to start the example. Move Form1 so you can see both forms, and then minimize or maximize the form and observe the behavior of Form2.

Private Sub Form_Load ()
   Form2.Show   ' Show Form2.
End Sub

Private Sub Form_Resize ()
   ' If parent form is minimized...
   If Form1.WindowState = vbMinimized Then
 ' ...hide Form2.
      Form2.Visible = False   
   ' If parent form isn't minimized...
 Else   
      ' ...restore Form2.
  Form2.Visible = True   
   End If
End Sub