How do I call a form and close a form in the same event. For example:
private void iniciar_Click(object sender, EventArgs e)
{
Close();
Frm1 newForm2 = new Frm1();
newForm2.ShowDialog();
}
How do I call a form and close a form in the same event. For example:
private void iniciar_Click(object sender, EventArgs e)
{
Close();
Frm1 newForm2 = new Frm1();
newForm2.ShowDialog();
}
This is done by placing the second form in a Thread:
public static void ThreadProc()
{
Application.Run(new Frm1());
}
private void iniciar_Click(object sender, EventArgs e)
{
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));
t.SetAppartmentState(ApartmentState.STA);
t.IsBackground = true;
t.Start();
this.Close();
}
Hello, I was having the same problem as our colleague @AndersonBP mentioned, there searching the internet, I found a response from @JuniorTunjr that was easier to understand and solved my problem.
private void btnIniciar_Click(object sender, EventArgs e)
{
this.Hide();
Form f = new frm2();
f.Closed += (s, args) => this.Close();
f.Show();
}
Use the this.Hide (); to close your LOGIN screen, as in the example below.
private void iniciar_Click(object sender, EventArgs e)
{
Frm1 newForm2 = new Frm1();
this.Hide(); // use dessa maneira.
newForm2.ShowDialog();
}