Question

I've two forms (called form1 as mdi container and form2) with an opentoolstripmenuitem in form1, when opentoolstripmenuitem clicked form2 called and opentoolstripmenuitem become disable, but when i click closebox in the top right of form2 the opentoolstripmenu still disable, i want it to enable again when closebox clicked.

Here my code in form1 :

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
    openToolStripMenuItem.Enabled = false;
    Form2 newMDIChild = new Form2();
    newMDIChild.MdiParent = this;
    newMDIChild.Show();            
}

any advice??

Was it helpful?

Solution

In the click handler, create a handler for the Closing or Closed event for Form2:

newMDIChild.FormClosed += new FormClosedEventHandler(newMDIChild_FormClosed);

and

void newMDIChild_FormClosed(object sender, FormClosedEventArgs e)
{
        openToolStripMenuItem.Enabled = true;
}

OTHER TIPS

Simple Just use ShowDialog() on form and enable it after Showdialog

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
openToolStripMenuItem.Enabled = false;
Form2 newMDIChild = new Form2();
newMDIChild.MdiParent = this;
newMDIChild.ShowDialog(); 
openToolStripMenuItem.Enabled = true;           
}

The next code after showdialog will not be executed until the dialog is close

Hope it works

Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top