I am having problems closing out a C# windows form app. It will currently just give me a blank form with no title or anything. I need to find a way to close this little unknown window.
I Have 2 form pages one for a login screen and one for the actual app. All being run by a program.cs file.
program.cs
...
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new PROG1());
}
This is just the basic main created by visual studio to run my program.
Then we have the main program
PROG1.cs
...
public PROG1()
{
Login LoginForm = new Login();
DialogResult a = LoginForm.ShowDialog();
if(LoginForm.ValidLogin == 1) {
InitializeComponent();
} else {
Application.Exit(); //FAIL
}
}
You can see that the first the program.cs file calls PROG1.cs which calls an instance of login.cs. If you insert a valid login the login page will close and the main PROG1 will show as it should. However if you simply click the red X to close login form it comes to Prog1 and LoginForm.ValidLogin != 1 so it does not Initialize the form and will try to close the form. This will just leave me the uninitialized form instead of closing it out. If I do a this.close() instead it will give me a runtime error.
Any Ideas?