Close form in c #

-1

Open form button:

 frmCatalogos formulario = new frmCatalogos();
        this.Hide();
        formulario.ShowDialog();
        this.Show();

All right up there. The problem arises when I click on a button in the following form. performs all the complete tour and then returns to this.Show(); as this may be because if you see the operation I intend only to create a single instance of form.

    
asked by DoubleM 29.01.2018 в 04:45
source

1 answer

5

To have only 1 instance of the form, you should do something like this:

public partial class Form1 : Form
{
    private Form2 formulario;//Declarar aqui la variable del formulario

    public Form1()
    {
        InitializeComponent();
        this.formulario = new Form2();//Inicializarlo una sola vez

    }

    private void button1_Click(object sender, EventArgs e)
    {
        this.Hide();
        this.formulario.ShowDialog();//Llamarlo de este modo, sin poner el New
        this.Show();
    }

}
    
answered by 29.01.2018 в 11:47