Question How to close an application?

Cobalt

Member
Joined
May 28, 2008
Messages
21
Programming Experience
3-5
Hello,

I have two forms, Login and Main. The VB project is set to load Login first. If the user's credentials are correct I call the main form with Main.Visable = True and hide the Login form with Me.visable = false

While this works, if I close down the Main form using the normal X button, the form closes but the application does not. I assume because the Login form is stil hidden in the background.

How can I get the application to close completely (both forms) when the X button is clicked on the Main form?

Thanks
 
You should use the application Startup event to show your login dialog, if failing login you just cancel the startup. Set main form as project startup form.
 
You should use the application Startup event to show your login dialog, if failing login you just cancel the startup. Set main form as project startup form.

Thanks John, do you mean have the Login form being called on the Main Form OnLoad function?

I did give something like this a go. Not having the complier in front of me I had something like this.

VB.NET:
// Inside the Main form OnLoad function
login.visable = true
me.visable = false

// Then on the login form, after being succesful I had the reverse
main.visable = true
me.visable = false

This, when the app was loaded brought up both Main and Login screens for some reason.

Am I going about it the correct way, with the Visable attribute, or should I be using something else? Is the 'Startup Event' you described the OnFormLoad?

Thanks again.
Rob (may as well use my real name, seems a bit daft otherwise :D)
 
No, I literally meant using the application Startup event. Go to project properties and click the "application events" button. Select the Startup event. Here you ShowDialog your login form and set e.Cancel as appropriate.
 
This is far too easy.
Try this
put the code in your main form's unload event.
private sub frmMain_unload() 'The main form's unload event
end
end sub
 
This is far too easy.
Try this
put the code in your main form's unload event.
private sub frmMain_unload() 'The main form's unload event
end
end sub

That doesn't make any sense at all

Not to mention that form's haven't had an "Unload" since vb6, which was crappy at best
 
Oh extremely sorry It should have been something like this

That doesn't make any sense at all

Not to mention that form's haven't had an "Unload" since vb6, which was crappy at best

Sorry dude it should have been like this :eek:

VB.NET:
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        'Do whatever u want to do and to close the form use end
        End
    End Sub
 
But if he cancels the app startup event based on the result of the login form, he wouldn't need to force the entire app to end in any formclosing event. Which is what John's already said.
 
Back
Top