CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2001
    Location
    Salt Lake City, UT
    Posts
    135

    Detect # of forms opened automatically

    Hi!

    I would like to be able to automatically count the number of forms currently opened when the user clicks a menu item. How do I do this?
    I basically want to make sure each child form is unloaded before i close the parent mdi form.

    Any help is appreciated!

    ~goddess
    [email protected]
    "There are no stupid questions, but there are a lot of inquisitive idiots."

  2. #2
    Join Date
    Jan 2001
    Posts
    165

    Re: Detect # of forms opened automatically

    Forms.Count

    -K


  3. #3
    Join Date
    Jun 2001
    Location
    Memphis, TN
    Posts
    146

    Re: Detect # of forms opened automatically

    Hey there, see if this code does what you're looking for...


    Dim frm as Form
    for Each frm In Forms
    if frm.MDIChild = true then Unload frm
    next




    I haven't tested that so I can't swear on my life that it will work but maybe get you in the right direction? Good luck!

    Jeff


  4. #4
    Join Date
    Apr 2001
    Location
    Salt Lake City, UT
    Posts
    135

    Re: Detect # of forms opened automatically

    is there such a thing as an 'isLoaded' check? i think that would capture what I am trying to do.

    The code you posted gave me an 'invalid property value' error, but it was a great idea!

    ~goddess
    [email protected]
    "There are no stupid questions, but there are a lot of inquisitive idiots."

  5. #5
    Join Date
    Apr 2001
    Location
    Salt Lake City, UT
    Posts
    135

    Re: Detect # of forms opened automatically

    Actually, I changed it to frm.visible = true then . . .
    and it worked great!!
    Thanks for the kick start!

    ~goddess
    [email protected]
    "There are no stupid questions, but there are a lot of inquisitive idiots."

  6. #6
    Join Date
    Jun 2001
    Location
    Memphis, TN
    Posts
    146

    Re: Detect # of forms opened automatically

    Hahaha, I just tested some code with frm.Visible and it worked out so as I came back to post it for ya I noticed your message- great minds...


  7. #7
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    78

    Re: Detect # of forms opened automatically

    This adds to what everyone else has posted:

    in parent form:

    option Explicit

    private Sub MDIForm_Load()
    ' or form1.show if you want
    Load Form1 'child
    Load Form2 'child
    Load Form3 'not a child
    End Sub

    private Sub MDIForm_QueryUnload(Cancel as Integer, UnloadMode as Integer)
    Dim intCount as Integer

    ' unloads all forms
    ' note forms(0) is the parent form which as you know will be unloaded
    ' by the its own unload method
    ' The forms collection begins at 0 and Forms.Count gives the number of
    ' forms in the collection, so you need to -1
    for intCount = (Forms.Count - 1) to 1 step -1
    If Forms(intCount).MDIChild then
    MsgBox Forms(intCount).Name & " is a child"
    else
    MsgBox Forms(intCount).Name & " is not a child"
    End If
    Unload Forms(intCount)
    next
    End Sub






Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured