How can I save a form using C # code?

-1

Hello good afternoon I have a doubt in the C # language create a form with the code of form a = new form (); a.show (); and I want to save that form in the project because only with that code the form is opened but it is not saved in the project. Is there any way to save that form in the project?

    
asked by Emmanuel Aguilar 18.02.2018 в 23:28
source

1 answer

0

If you have two or more forms, you need an object to store the information, since when you move from one form to another, you are instantiating a new form (In other words, you start again), therefore you can follow this example.

Structure of the person (DTO):

public class Persona
{
    public string Nombre {get; set;}

    public Persona(){}
}

Main Form, which starts the application

public class FormularioPrincipal
{   
    public Persona Persona = null;

    public void AbrirFormulario2()
    {
        Persona persona = new Persona();
        Persona = persona;
        FormularioPersona form = new FormularioPersona(ref persona);
        this.Hide();
        form.Show();
    }
}

Form which fills all the information of the person (Vista)

public class FormularioPersona
{
    public Persona Persona = null;

    /*Constructor del formulario, la cual hace referencia al objeto persona del formulario principal*/
    public FormularioPersona (ref persona)
    {
        Persona = persona;
    }

    /*Método para completar la informacción de una persona*/
    public void CompletarInformacionPersona()
    {
        Persona.Nombre = textbox.Text;
        this.Close();
    }
}

Greetings, I hope I have helped you.

    
answered by 20.02.2018 / 16:12
source