Let’s say you have a main form. Call it frmMain.
In frmMain before IntializeComponent
frmLogin loginForm = new frmLogin();
//Set the dialog result on login form depending on ok and cancel button
//close the application if user wants to cancel
if(loginForm.DialogResult == DialogResult.Cancel)
this.Close();
//else you can continue to call your frmMain initializeComponent method
solved How to open one window and close another on button click [closed]