Results 1 to 4 of 4

Thread: [RESOLVED] Form closing when it shouldn't be.

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Resolved [RESOLVED] Form closing when it shouldn't be.

    Hi all,

    I have created a splash screen and it fades in. When the splash screen closes, the main form (MDI) should open. The main form opens but then immediately closes. I am not sure what's going on, any ideas? Here is my code. Thanks.
    vb Code:
    1. Public Class frmSplash
    2.     Private Sub frmSplash_FormClosing(ByVal sender As Object, _
    3.                                       ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    4.  
    5.         'Opem the MDI form.
    6.         frmMain.Show()
    7.     End Sub
    8.  
    9.     Private Sub frmSplash_Load(ByVal sender As Object, _
    10.                                ByVal e As System.EventArgs) Handles Me.Load
    11.  
    12.         'Fade form in.
    13.         For i As Integer = 0 To 100 Step 1
    14.             Me.Opacity = i / 100
    15.             Me.Refresh()
    16.             Threading.Thread.Sleep(50)
    17.         Next i
    18.  
    19.         Me.Close()
    20.     End Sub
    21. End Class

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Form closing when it shouldn't be.

    That would be because your splash screen is the startup form and your app is set to exit when the startup form closes. You could set the application to exit when all forms have closed but I would recommend doing things rather differently.

    My first choice would be to display the splash screen not as the startup form but as the splash screen, as intended. You can then use my Window Animation thread in the CodeBank to learn how to fade a form in and out using the OS rather than a Timer.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Member VB6 to Vb2010's Avatar
    Join Date
    Dec 2010
    Posts
    38

    Re: Form closing when it shouldn't be.

    Try changing the shutdown mode in your project properties from "when startup form closes" to "when last form closes".

    I was too slow....

  4. #4

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