At this point it is worth mentioning how you call the other Forms, so it close according to the call order, below I will cite an example that I use.
Before you go calling any form by the event button_Click, let’s instantiate first at the beginning of our form, first let’s call simply our form_2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Abrindo_e_Fechando_Forms
{
public partial class Form1 : Form
{
public Form_2 MeuForm2 = null;
public Form_3 MeuForm3 = null;
public Form1()
{
InitializeComponent();
}
private void btn_abrir_form_2_Click(object sender, EventArgs e)
{
Form_2 Form2 = new Form_2();
Form2.Show();
}
}
}
Now let’s make like that, the Form2 call the Form3, and when you click close on the form2 it closes the form 3
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Abrindo_e_Fechando_Forms
{
public partial class Form_2 : Form
{
public Form_3 MeuForm3 = new Form_3();
public Form_2()
{
InitializeComponent();
}
private void btn_abrir_form_3_Click(object sender, EventArgs e)
{
MeuForm3.Show();
}
private void btn_fechar_formAtual_e_aberto_Click(object sender, EventArgs e)
{
MeuForm3.Hide();
this.Close();
}
}
}
As you can see I created a new instance of form3 in Form2
public Form_3 MeuForm3 = new Form_3();
In other words, by instantiating Form3, it becomes our object and we can manipulate it in the best way possible. I hope it has helped in some way!
Atte!
Close all you want, what is the difficulty?
– Maniero