K...this is making me crazy! First, I only have two forms...
The Splash screen is the main()
I used to do this:
static void Main()
{
Application.Run(new frmSplashScreen());
}
....Initialize Code...
private void frmSplashScreen_Load(object sender, EventArgs e)
{
this.Update();
this.Show();
frmCommunities mainForm = new frmCommunities();
this.Hide();
mainForm.Show();
}
This was no problem and worked fine.
Now I am working in Visual Studio 2005 and this doesn't work. What the HE!!
Some noteable differences. VS '05 creates a program.cs which is the Main()
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[MTAThread]
static void Main()
{
Application.Run(new frmSplash());
}
}
...then there is the Designer.cs that is a partial class and contains the
InitializeComponent code...
I placed my code in the partial class and here it is....
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System.Reflection;
using System.IO;
namespace eScheduleMobile
{
public partial class frmSplash : Form
{
#region variables
private DataManager DM;
private frmLogin Login;
#endregion
public frmSplash()
{
InitializeComponent();
}
private void Splash_Load(object sender, EventArgs e)
{
this.Show();
this.Refresh();
if (!ConfigApp())
{
Application.Exit();
}
Login.Show();
Login.Refresh();
this.Hide();
}
private bool ConfigApp()
{
bool AppReady = false;
DM = new DataManager();
try
{
if (!initDB())
{
this.lblMessage.Text = "Failed to create data file.
Application will exit.";
this.lblMessage.Refresh();
AppReady = false;
}
else
{
this.lblMessage.Text = "Data file was updated.";
this.lblMessage.Refresh();
AppReady = true;
}
if (!initLogin())
{
this.lblMessage.Text = "Login form could not be created.";
this.lblMessage.Refresh();
AppReady = false;
}
else
{
this.lblMessage.Text = "Configuration complete.";
this.lblMessage.Refresh();
AppReady = true;
}
}
catch
{
}
return AppReady;
}
private bool initDB()
{
try
{
//Check to see if data file (sdf) was created.
//If not, 'CheckDB will create one.
if (DM.CheckDB(false))
{
//Now we add Tables and Indices using the
'eScheduleMobile.DB.xml' config file
if (!DM.CreateDatabase())
{
this.lblMessage.Text = "Data Failure. Failed to
create tables.";
this.lblMessage.Refresh();
return false;
}
if (!DM.CreateIndices())
{
this.lblMessage.Text = "Data Failure. Failed to
create indices.";
this.lblMessage.Refresh();
return false;
}
this.lblMessage.Text = "Data file created.";
this.lblMessage.Refresh();
}
}
catch
{
}
//Return true if DB was created or already exists.
return true;
}
private bool initLogin()
{
Login = new frmLogin();
return true;
}
private void btnContinue_Click(object sender, EventArgs e)
{
Login.Show();
Login.Refresh();
this.Hide();
}
}
}
....K, The Splash page shows and displays updates as data is created and the
login form is created. The login form should be displayed and the Splash page
hidden. It works right up until the Load event ends. Then the hidden Splash
page is AGAIN displayed, even after I told it to Hide.
Side note: WORKS GREAT IF I CLICK THE BUTTON. Just not in the load even
....WHY, why oh why....
--
Charcoal
Going Mobile...Keep me moving.