Visual basic:Form open/close help?

Visualbasic

Newcomer
Joined
Sep 18, 2011
Messages
1
I have 3 forms.
My first form is a load screen and hides after progress bar loads so i cant manually close nor do i want any one to see it again. So i need a way for when form 2 closes my form 1 closes too not just hides i need the program to actually close
 
Hi, and welcome to the forum!

You'll probably find you get the best answers if you provide as much relevant information as possible. I don't know how you are managing/showing/hiding/closing these forms, but I'll try to give the best answer I can. It sounds like the first form is a splash screen, so I'm going to go on that assumption.

The best answer depends on how you are showing the splash screen to begin with. If you are using the "application framework" feature, Microsoft offers an explanation of how you should manage your splash screen.


If you are not using the application framework, you'll want to modify your program's Sub Main to get the behavior you want. Ideally, you should be closing the splash screen as soon as you are done with it, not just hiding it. However, this would cause an issue if the splash screen is your "Startup Object" because VB would think that the splash screen is your main form, and the program would end when the splash screen is closed. To fix this, you would want to make the following change to your sub main:
Code:
[COLOR="SeaGreen"]' change
[/COLOR]
Application.Run(New [i]splashScreenForm[/i]())

[COLOR="SeaGreen"]' to
[/COLOR]
Application.Run()
Dim splash As New [i]splashScreenForm[/i]()
splash.Show()
Or, if you don't have a sub main, you can add a new module to your project and add a sub main.
Code:
Sub Main()
    Application.EnableVisualStyles()
    Application.Run()
    Dim splash As New [i]splashScreenForm[/i]()
    splash.Show()
End Sub
You'll also want to make sure your "Startup Object" is set to "Sub Main" in the project properties. These changes result in your program not having a main form. A program usually ends when the main form is closed, but when no form is the main form, you simply have to tell the program when to end explicitly by calling Application.Exit (you'll probably want to call this in the Form.Closed event of one of your forms).

Hopefully, that helps you solve your problem.
 
hey 'Visualbasic'

this is a function inbuilt in VB2010, so it takes like two seconds
Please see attached image (if it works obv
first of all you need to open the "My Project" int the "Solution Explorer".
then you need to make sure that your "Startup Form" is your main form.
then you need to change your "Splash screen" to what ever your splash screen is.
once this is done all will work fine

or if you really want to have the loading bar then you could use this code for your 'form 2'

Code:
    Private Sub [COLOR="Red"]NameOfForm[/COLOR]_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        End
    End Sub
 

Attachments

Back
Top