Results 1 to 11 of 11

Thread: Closing Forms

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Chesterfield, UK
    Posts
    298

    Closing Forms

    I have a splash screen form (frmSplash) and also a MDI Form (frmMain).

    frmSplash loads first and has a timer on it (tmrSplash) it runs the following code on the tick event :

    VB Code:
    1. Private Sub tmrSplash_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrSplash.Tick
    2.         Dim objMain As New frmMain()
    3.         tmrSplash.Enabled = False
    4.         objMain.Show()
    5.         Me.Close()
    6.     End Sub

    But the Me.Close() closes the entire application.

    What am I doing wrong?

    Regards,


    Matt.

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Thats the way it should be, cause the splash form controls the life cycle of your application. Try starting your application from a Sub Main and then after closing the splash form show the main form.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Sounds like you might have your spalsh screen as the startup form.

    I think a better way to do it is have your MDI form call the splash screen and then close it when the MDI form has finished loading. I am sure there are other ways to do it as well.

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by VBCrazyCoder
    I think a better way to do it is have your MDI form call the splash screen and then close it when the MDI form has finished loading. I am sure there are other ways to do it as well.
    But you know that you can not start the main form -better say startup form - of your project hidden, right?
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  5. #5
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    We actually posted at the same time

    I'm actually am a big fan of using sub main as you suggested, but my thought was for this the easiest way would be to do it in the load event of the MDI form. You could make the splash screen TopMost, etc.....

    But I was not aware of not being able to have a hidden form as a startup form

    Is that a bug?

  6. #6
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by VBCrazyCoder
    But I was not aware of not being able to have a hidden form as a startup form

    Is that a bug?
    Seems like a feature.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Chesterfield, UK
    Posts
    298

    Thanks

    Thanks for your help.

    I ended up using the MDI form as the startup form and loading the Splash Screen, Setting the Opacity to 0% of the MDI form then changing it back to 100% after the splash screen had been closed.

    Thanks Again.

  8. #8
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    So in essence, it was hidden. Cool!

  9. #9
    Addicted Member
    Join Date
    Jul 2000
    Location
    Scotland
    Posts
    184
    Can anyone help me with an extension of this problem?

    I've a MDI app with a start up Child form (splash) which closes whenever another Child (user type) form is opened.

    I'd like the splash Child form to return when all other Child forms are closed.

    How will I know if the last Child form has gone and I can show the splash again?

    Raising events is no use either because I've already built about 20 forms

    I've tried an array but some of the child forms have sub forms of their own.

    Looked at the properties of MIDlist menu without success.....

    Any ideas?

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Chesterfield, UK
    Posts
    298
    What about the following :

    Pop this in a module :

    VB Code:
    1. Module Module1
    2.     Public Forms As New FormsCollectionClass()
    3. End Module
    4.  
    5. Class FormsCollectionClass : Implements IEnumerable
    6.     Private c As New Collection()
    7.     Sub Add(ByVal f As Form)
    8.         c.Add(f)
    9.     End Sub
    10.     Sub Remove(ByVal f As Form)
    11.         Dim itemCount As Integer
    12.         For itemCount = 1 To c.Count
    13.             If f Is c.Item(itemCount) Then
    14.                 c.Remove(itemCount)
    15.                 Exit For
    16.             End If
    17.         Next
    18.     End Sub
    19.     ReadOnly Property Item(ByVal index) As Form
    20.         Get
    21.             Return c.Item(index)
    22.         End Get
    23.     End Property
    24.     Overridable Function GetEnumerator() As _
    25.     IEnumerator Implements IEnumerable.GetEnumerator
    26.         Return c.GetEnumerator
    27.     End Function
    28. End Class

    Then on the closed event on the forms (not great I know) put the following :

    VB Code:
    1. Dim i As Integer = 0
    2.         Dim f As Form
    3.  
    4.         For Each f In Forms
    5.             If f.IsMdiChild Then
    6.                 i = i + 1
    7.             End If
    8.         Next
    9.  
    10.         If i = 0 Then
    11.             ' Open Another Form
    12.         End If

    Hope this is of use.

    Matt.

  11. #11
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by Steven McGarva
    Can anyone help me with an extension of this problem?

    I've a MDI app with a start up Child form (splash) which closes whenever another Child (user type) form is opened.

    I'd like the splash Child form to return when all other Child forms are closed.

    How will I know if the last Child form has gone and I can show the splash again?

    Raising events is no use either because I've already built about 20 forms

    I've tried an array but some of the child forms have sub forms of their own.

    Looked at the properties of MIDlist menu without success.....

    Any ideas?

    Why not just make sure the position and size of the SplashChild is such that it is hidden behind any other child form visible?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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