Question form closing

FuZion

Well-known member
Joined
Jan 28, 2007
Messages
47
Programming Experience
Beginner
Hello,

I have an MDI container and a child login form. I set an event to cancle the close event on the child form because the user has to login. But if I try to close the full application.. via the parent form.. the app doesn't close, I'm assuming this is because of the event i created. How do I fix this?


Thanks!
 
g

Try this, but subtitue "callForm" with your own variable name.
You're setting the form ("Form2") to a variable, so you can add commands to it. Such as Mdiparent = me (This tells the form2 that its parent is form1).

Put in form1:
VB.NET:
Dim callForm As New Form2
        callForm.MdiParent = Me
        callForm.Show()
 
You could add an application global variable (boolean) in which when you close the main app in it's FormClosing event you set this variable to True and in your Login form's FormClosing event you allow the form to be closed if that boolean is True
 
Well my first idea was the global.. I had variable changed when the MDI parent was closed (frmMain.formClosing). However, my child form didn't read the global as true until I clicked close a second time. Does that make sense? Is there a better way to do it?
 
Why not use the Application Startup event to show the login dialog, if failing you can cancel the start of the application altogether and the main form won't be called in the first place.
 
But what if the form loads and the user accidentally exits the login form.. they wouldn't be able to reopen it and thus wouldn't be able to access the application.
 
Either they make a successful login and for which you return DialogResult.OK and let main app start, or they don't and app exits when login dialog closes.
Of course they can "reopen" it, they can start app as many times they wish, but don't get passed login form unless they login.
 
I figured they could reopen it, but I'd rather my application be a tad more user friendly.. there is no way to prevent them from closing just that MDI child form while allowing the MDI parent form to be closed?
 
MDI child form?? I thought you were making a login form? That's supposed to show first, before the application starts.
 
Or the MDI main form loads and the login form is modally shown (IE the login form is shown but the parent form is frozen until a successful login occurs or the main app unfreezes to close because the login form was closed without valid login)
 
Thats exactly what I am doing.. the login form is an MDI child and everything else is frozen until they login. Does the other way work better?
 
Back
Top