private void buttonLogoff_Click(object sender, EventArgs e) { GlobleData.IsUserLoggedIn = false; LoginMsg = "User Successfully logged off"; this.Visible = false; loginEntry = new LoginForm(); if (loginEntry.ShowDialog() == DialogResult.OK) { if (this.Visible == false && GlobleData.IsUserLoggedIn) { this.Visible = true; } LoginMsg = "User Successfully logged in"; } }
private void MainForm_Load(object sender, EventArgs e) { _hide(); LoginForm loginEntry = new LoginForm(); if (loginEntry.ShowDialog() == DialogResult.OK) { Login(); show(); } if (GlobleData.IsUserLoggedIn == false) { Application.Exit(); } }
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { } else if (e.Button == MouseButtons.Left) { FormCollection forms = Application.OpenForms; if (this.WindowState == FormWindowState.Minimized && forms["LoginForm"] == null) { LoginForm loginEntry = new LoginForm(); if (loginEntry.ShowDialog() == DialogResult.OK) { Login(); show(); CloseAllChildForm(); } } } }
// The handler when attempting to start another instance of this application // We can customize the logic here for which form to activate in different // conditions. Like in this sample, we will be selectively activate the LoginForm // or MainForm based on the login state of the user. private static void StartNewInstance(object sender, StartupNextInstanceEventArgs e) { FormCollection forms = Application.OpenForms; if (forms["LoginForm"] != null) { forms["MainForm"].Hide(); forms["LoginForm"].Activate(); } else if (forms["LoginForm"] == null && GlobleData.IsUserLoggedIn == false) { MessageBox.Show("22"); LoginForm f = new LoginForm(); if (!(f.ShowDialog() == DialogResult.OK)) { forms["MainForm"].WindowState = FormWindowState.Maximized; forms["MainForm"].Show(); } else { forms["MainForm"].Close(); } } else if (forms["MainForm"] == null && GlobleData.IsUserLoggedIn == true) { MessageBox.Show("23"); LoginForm f = new LoginForm(); if (!(f.ShowDialog() == DialogResult.Cancel)) { forms["LoginForm"].Show(); } } else if (forms["MainForm"] != null && GlobleData.IsUserLoggedIn == false) { LoginForm f = new LoginForm(); if (f.ShowDialog() == DialogResult.OK) { forms["MainForm"].WindowState = FormWindowState.Maximized; forms["MainForm"].Show(); } } else if (forms["MainForm"] != null && GlobleData.IsUserLoggedIn == true) { LoginForm f = new LoginForm(); if (f.ShowDialog() == DialogResult.OK) { forms["MainForm"].Show(); forms["MainForm"].WindowState = FormWindowState.Maximized; } } else if (forms["MainForm"] != null && GlobleData.IsUserLoggedIn == true && forms["MainForm"].WindowState == FormWindowState.Minimized) { MessageBox.Show("4"); LoginForm f = new LoginForm(); if (f.ShowDialog() == DialogResult.OK) { forms["MainForm"].WindowState = FormWindowState.Maximized; forms["MainForm"].Show(); } } else if (forms["MainForm"] != null && GlobleData.IsUserLoggedIn == true && forms["MainForm"].WindowState == FormWindowState.Maximized) { MessageBox.Show("5"); LoginForm f = new LoginForm(); if (f.ShowDialog() == DialogResult.OK) { forms["MainForm"].WindowState = FormWindowState.Maximized; forms["MainForm"].Show(); } } else { MessageBox.Show("6"); } }