Hide or close an MDI Children form

2

Hi, I have an MDI form (frmPrincipal) where I open an MDI Children form (frmListerateClients).

Within this mdi children when closing the form I launch a form (frmOpciones) that allows you to make a couple of quick procedures that you can either press one of them or cancel the form.

  • If the frmOptions is canceled we will remain in modal the frmListadoClientes

  • If one of the frmOptions buttons is activated, a 4th form is opened (frmTPV), so I try to hide the third form (frmOpciones) and show this last open form in a modal form, for this I use this code

Code to open the Options form

frmOpciones frm = new frmOpciones (param1 , param2);
frm.ShowDialog();   

From the form frmOpciones (3rd form) I open the corresponding option to open the 4th form that I launch with this code

private void btnStock_Click(object sender, EventArgs e)
{
    this.Close();
    Form f2 = new frmTPV(param1 , param2 , param3);
    f2.MdiParent = this.ParentForm;
    f2.ShowDialog();
}

Here what I try to do is that before launching this 4th form close the third but I do not get it, I have also tried this.Hide () without success.

The problem I have is how to make this form not shown or hidden.

Thanks

    
asked by ilernet 04.07.2017 в 09:58
source

2 answers

2

Good morning, the following has worked for me:

private void btnStock_Click(object sender, EventArgs e)
{
    //this.Close();
    Form f2 = new frmTPV(param1 , param2 , param3);
    f2.MdiParent = this.ParentForm;
    f2.ShowDialog();
    this.Hide();
}

You already tell me if it worked for you.

Greetings !!

    
answered by 04.07.2017 / 10:53
source
2

Good morning,

What you are trying to do is like a menu window where you choose what action to perform and open a window or another depending on the button that is clicked.

The easiest way to carry out this action is by calling the form frmOpciones des del frmPrincipal and depending on the button that is clicked, the same form returns a variable so that frmPrincipal interprets it and opens the form that is desired, and from this one way you assure yourself that it will open with that MDI and frmOpciones will be closed:

Code for frmOptions:

public int OpcionMenu { get; set; } //Declaramos una variable como property para recogerla en frmPrincipal.

TPV click event:

private void TPVbutton_Click(object sender, EventArgs e)
{
    OpcionMenu = 1; //Número que asociarás al formulario que deseas abrir
    this.DialogResult = System.Windows.Forms.DialogResult.Yes;
}

Code for frmPrincipal:

int opcionMenu;
frmOpciones frm = new frmOpciones (param1 , param2);
frm.ShowDialog();
if (frm.DialogResult = System.Windows.Forms.DialogResult.Yes)
{
   opcionMenu = frm.OpcionMenu; //Recogemos el valor de frmOpciones
   if (opcionMenu == 1)
   {
       //Abrimos el frmTPV
   }
}

I hope it helps you.

    
answered by 04.07.2017 в 11:54