I have 3 forms - the main form is Form1 the others are a splash form and then a login screen. Splash screen displays first and populates servers. Then, the frmAppLogin is shown, user enters a hardcoded password and result returns to form1.
public Form1()
{
_assembly = Assembly.GetExecutingAssembly();
Stream icon = _assembly.GetManifestResourceStream.....
this.Icon = new Icon(icon);
Thread t = new Thread(new ThreadStart(SplashScreen));
t.Start();
InitializeComponent();
PopulateServers();
//Thread.Sleep(800);
Form frmLogin1 = new frmAppLogin();
t.Abort();
frmLogin1.ShowDialog();
DialogResult res = new DialogResult();
res = frmLogin1.DialogResult;
if (res == DialogResult.OK)
{
_LoggedIn = true;
}
else
{
_LoggedIn = false;
}
}
This is the code for form1_load:
private void Form1_Load(object sender, EventArgs e)
{
if (_LoggedIn)
{
try
{
blah blah........
}
catch
{
MessageBox.Show("Error accessing resources!");
}
}
else
{
this.Close();
}
}
And the code for the Login form:
public frmAppLogin()
{
InitializeComponent();
this.WindowState = FormWindowState.Normal;
}
private void btnAppLogin_Click(object sender, EventArgs e)
{
if (txtAppPass.Text.ToString() == requiredPass)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
txtAppPass.Clear();
txtAppPass.Focus();
MessageBox.Show("Incorrect Password");
}
}
Problem is when the splash screen disappears, the log in form pops up for a split second but immediately minimizes to the taskbar.
Startposition is set to CenterScreen and WindowState Normal via GUI.
Also this only happens when I run the application.exe in (or copy it from) the debug folder, I.E. it does not happen when I debug in Visual Studio 2010.
Edit: Just to add this in, I have also tried:
private void frmAppLogin_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
}
Which didn't help.