-2
private void btn_Login_Click(object sender, EventArgs e)
{
    ManageMent.login_check(txtUserName.Text, txtPassword.Text);

    if (ManageMent.Login_Check!=false)
    {
        Control_Center control_panel = new Control_Center();

        control_panel.Show();

        this.Hide();
    }
}

im using these codes these codes behind my login button, but this leave the main login form hidden somewhere and when i m closing the control panel it ix still running behind, i want to close it immediately when the authentication is successful.. i tried this.Close(); but it restrict the control panel to open

Ilya Ivanov
  • 23,148
  • 4
  • 64
  • 90
Rehan Manzoor
  • 87
  • 1
  • 1
  • 8

2 Answers2

0

the are some more options that you have ....

Actually i think your Login Form Runs as main thread , so closing it will not make you go with another form within that, i mean main thread , so trick is to go with simple threading ....

if (ManageMent.Login_Check!=false)
    {
            new System.Threading.Thread(new System.Threading.ThreadStart(()=>{
                Application.Run(new Control_Center());
            })).Start();

            this.Dispose();
}

if you only want to close all form(s) at last , i mean just kidding , then

    if (ManageMent.Login_Check!=false)
        {
          this.Hide();
          Control_Center control_panel = new Control_Center();
          control_panel.ShowDialog(this);
          this.Close();
        }
internals-in
  • 4,798
  • 2
  • 21
  • 38
0

I think you should create your application with Control_Center

Application.Run(new Control_Center());

before your control_center form is shown, you should create a LoginForm. For example you can do when the form is loaded.

public partial class Control_Center: Form
{
    public Control_Center()
    {
        InitializeComponent();
    }

    private void Control_Center_Load(object sender, EventArgs e)
    {
        LoginForm loginForm = new LoginForm();
        var authorizationResult = loginForm .ShowDialog();
        if (authorizationResult  != System.Windows.Forms.DialogResult.OK)
        {
            this.Close();
        }
    }
}
Dmitrii Dovgopolyi
  • 6,231
  • 2
  • 27
  • 44