• Detect if Form is open (VB6)

    Author
    Topic
    #377457

    Can anyone help me with a method to detect if a VB form is currently displayed?

    I have an MDI form that I am displaying child forms in, and I have a menu bar to switch between the child forms. I want to hide or unload one form before the other displays.

    Viewing 3 reply threads
    Author
    Replies
    • #621642

      You can use an API call: either GetWindow if it’sa child window of another open window (form) or FindWindow if it’s a top level window.
      If the return value is zero, you know the window is NOT open.

    • #621738

      Why not just hide all of them before any load?

    • #621841

      This is a function I use to detect if a form is loaded, but you could change the syntax to test for various things…eg if it is the MDIForm.Activeform or if it is visible etc

      ‘ // ******************************************************************************
      ‘ // FUNCTION
      ‘ // IsFormLoaded(frm As Form) as Boolean
      ‘ //
      ‘ // PARAMETERS
      ‘ // fForm – The form to check to see if it is loaded

      ‘ // RETURN VALUE
      ‘ // if the form is loaded
      ‘ //
      ‘ // COMPONENTS USED
      ‘ // None
      ‘ //
      ‘ // NOTES
      ‘ // Returns true if the passed form is loaded in the forms collection
      ‘ // ******************************************************************************

      Public Function IsFormLoaded(fForm As Form) As Boolean
      On Error GoTo Err_Proc

      Dim x As Integer

      For x = 0 To Forms.Count – 1
      If (Forms(x) Is fForm) Then
      IsFormLoaded = True
      Exit Function
      End If
      Next x

      IsFormLoaded = False

      Exit_Proc:
      Exit Function

      Err_Proc:
      Msgbox Err.Description
      Resume Exit_Proc

      End Function

    • #621856

      Mike,

      Is it too simple-minded to use something like

      Dim frm As Form

      Set frm = Form1
      If frm.Visible = True Then
      frm.Hide
      End If

      That doesn’t load Form1 if it isn’t loaded already but it will hide it if it is visible.

    Viewing 3 reply threads
    Reply To: Reply #621856 in Detect if Form is open (VB6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel