I am working in C#. I am starting up in Program.Main. This opens frmSplash. frmSplash does a whole load of initialisation (Errs collection/database connection etc) and then opens frmGeneric. frmGeneric loads a bunch of information from the database and populates itself with controls as defined in the database. It might open other instances of frmGeneric. In fact, it may close itself before the other instances are closed.
The initialisation process occurs in frmSplash once it is visible, when the user clicks a 'Continue' button. At the moment, once the first instance of frmGeneric is shown, I call this.Hide()
in frmSplash, but I actually want frmSplash to unload.
If I call this.Close()
in frmSplash, even after frmGeneric is shown, the entire app closes.
Obviously, the last frmGeneric to close won't know that it is the last one (it's generic). How do I close down frmSplash after initialisation, without quitting the app?
private void cmdContinue_Click(object sender, EventArgs e)
{
Globals oG = null;
App oApp = null;
frmGeneric oForm = null;
try
{
txtStatus.Text = "Initialising Globals object...";
oG = new Globals();
// some other stuff redacted
txtStatus.Text = "Showing startup form...";
oForm = new frmGeneric();
oForm.Globals = oG;
if (!oForm.RunForm() throw new Exception("Could not run form");
// enough of me
this.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Application.Exit();
}
}
At the this.Close() in the above code, the entire app closes down, even though oForm has been loaded and is visible.