c # The bottom line is this. There are 2 forms in the application, one is the login form, the second where after the login information appears.

login form - loginForm info form - MainForm

With a successful login, the loginFrom closes and the MainForm starts.

//запуск главной формы MainForm mf = new MainForm(); //Закрытие и запуск this.Hide(); mf.ShowDialog(); 

in MainForm There are buttons to minimize the application to tray

 private void hideMenuStrip_Click(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Normal) { //this.WindowState = FormWindowState.Minimized; //если скрываем прогу, то скрываем везде кроме нотифи икон this.Visible = false; this.ShowInTaskbar = false; } } 

But when you hide the MainForm program, it either closes or the loginForm opens. And I need it to be minimized.

Closes if I add to all the hide buttons below

 this.Dispose(); 

In general, the problem manifests itself in that when the MainForm is minimized, for some reason, the Load function is started in the loginForm

    1 answer 1

    Your mistake is that you are trying to squeeze all the logic into window event handlers. Try transferring authorization related logic to Program.cs. First show the dialog window using ShowDialog() , and then open the main application window.

     LoginForm loginDialog = new LoginForm(); if (loginDialog.ShowDialog(null) == DialogResult.OK) { Password = loginDialog.TextBox1.Text; } loginDialog.Dispose(); if (Password=="MyPassword") Application.Run(); 

    See also [1] , [2] .