Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A question on closing forms 1

Status
Not open for further replies.

JohnVogel

Programmer
Apr 19, 1999
117
US
I am using a splash screen with a button on it. When the user presses the button, the splash screen hides itself and shows the main program form. When I close this form, I want to also make sure the hidden splash screen closes. Here is the code I am using to hide the splash form and open form1:

Code:
Dim other As New Form1()



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        other.Show()
        Me.Hide()

    End Sub

Now if I try the following code from within Form1, it closes everything (including Form1):

Code:
Dim SplashForm As New Splash()

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

        SplashForm.Close()
End Sub

So the question is when and how to close that hidden main splash form.

TIA,


-+{John Vogel}+-


 
it's because you instantiate form1 from within the splashform. Wich makes form1 a child of the splashform and it will close if the parent closes.
Make a third class and instantiate the two forms in there you could even make them shared if you want to.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Alternatively you could use a Sub Main, from which you initially open the splash screen and then the main form.

Hope this helps
 
I'm still pretty lost. Here's where I am at, code-wise:

Code:
Private Sub MainProgram_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Create the forms as frmsplash and frmmain
        Dim frmsplash As New SplashForm()
        Dim frmWizard As New WizardForm()

        'Show the splash Form

        frmsplash.Show()
        Application.DoEvents()

        'Indicate sleep (milliseconds) 
        System.Threading.Thread.Sleep(3000)

'Question: Rather then using the sleep, how can I wait until the splash form closes (user manually clicks button on splash) to load the next form?


        'close the splash form
        frmsplash.Close()

        'Show the frmWizard (WizardForm)
        frmWizard.Show()
        Application.DoEvents()

        'If the main form exits, then do the following:

         Close()

'Question: How do I tell when the main form exits and get control again?


    End Sub


Sorry if I seem hopelessly lost... this was just SO EASY in VB6...

TIA

-+{John Vogel}+-


 
this seems to work

Code:
Class Closingforms
    Shared frmsplash As splashform
    Shared frmwizard As wizardform

    Public Shared Sub Main()
        frmsplash = New splashform
        frmwizard = New wizardform
        If frmsplash .ShowDialog <> DialogResult.OK Then
            If frmwizard .ShowDialog <> DialogResult.OK Then

            End If
        End If
    End Sub
End Class

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
I got around this issue by calling the main form, then calling the splash screen using ShowDialog like JohnYingling said.

This acts like the old vb modal flag. Then when the splash closes, the code continues.
But you can not use this as a coverup while other code loads.

The side effect is when you close the main form, it closes the splash with it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top