Open the same form?

3

I want to open the same form, without having to open several more by clicking on my toolStripMenuItem2 or any other button I have my following code: '

private void notasDeEntradaToolStripMenuItem_Click(object sender, EventArgs e)
    {
        frmcontrol log = new frmcontrol();
        log.MdiParent = this;
        log.Show();
    }

I do not want to use the ShowDialog because I know that it will only open the frmcontrol but it will not let me perform the other tasks. (I just want to show the same form that is already open) I hope you can help me or understand me.

    
asked by SoyKrut 22.11.2017 в 01:55
source

1 answer

3

To avoid opening the same form twice, you could verify this by using the property OpenForms that represents a collection of the forms of your application, could verify the index whose value will be name of the form, if it is different from null , we only activate that form , otherwise we show it with show()

 if (Application.OpenForms["frmcontrol"] != null)
 {
    Application.OpenForms["frmcontrol"].Activate();
 }
 else
 {
   frmcontrol form = new frmcontrol();
   form.MdiParent = this;
   form.Show();
 }
    
answered by 22.11.2017 / 02:02
source