Call help form from various forms and return [duplicate] value

0

I have a project written in c # with three forms: form01, form02, form03 and everyone has a button that will call the help form. The Help form returns a value that must be received in the form that made the call. How can I do to receive the value in each form that makes the call?

    
asked by xpajo 25.09.2017 в 21:26
source

1 answer

1

What you should do is call your help form as a dialogue from the parent form:

var ayuda = new Ayuda().ShowDialog();

With this in mind (and assuming you have an action button on the help form) you must send a "result" of the dialogue, of course, setting the things you want to return as public properties:

public string Valor1 { get; set; }
public DateTime Valor2 { get; set; }

private void btnOk_Click(object sender,EventArgs e)
{
    this.Valor1 = "Texto";
    this.Valor2 = DateTime.Now;

    // Aquí devuelves el resultado del "diálogo".
    this.DialogResult = DialogResult.OK;
    this.Close();
}

and finally you receive it in the parent form:

private void btnAbrirAyuda_Click(object sender,EventArgs e)
{
    using(ayuda = new formularioAyuda())
    {
        var resultado = ayuda.ShowDialog();
        if (resultado == DialogResult.OK)
        {
            txtFormularioPadre.Text = ayuda.Valor1;
            ...
            ...
        }
    }
}
    
answered by 25.09.2017 / 22:09
source