Click here to Skip to main content
14,385,812 members
Rate this:
Please Sign up or sign in to vote.
See more:
I want to avoid my child form from appearing many times when a user tries to open the child form which is already open in MDIParent. the same Child Form Opens and I can see two child form are in MDI.The following code solve this problem
public partial class Home : Form
{
ShopMaster shopmaster=null;
private void shopMasterToolStripMenuItem_Click(object sender, EventArgs e)
{

if (shopmaster == null)
{
shopmaster = new ShopMaster();
shopmaster.MdiParent = this;
shopmaster.Show();
}
}
}
but if i close this child it never open again. so i just want that if child1 is open then it should not open again untill it get close. After closing it we can open it again.
Posted
Comments
[no name] 23-Aug-12 4:04am
   
If you find answer then click on accept answer(Green button) click on the stars(1-bad ,5 best).
This will help others to find the solution

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Make your variable as static

public static ShopMaster shopmaster=null;


then write the code in FormClosing event of your ShopMaster

private void ShopMaster_FormClosing(object sender, FormClosingEventArgs e)
      {
          string ans = (MessageBox.Show("Are you sure to Exit!", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question)).ToString();
          if (ans == "Yes")
          {
              Home.shopmaster=null;
          }
          else
          {
              e.Cancel = true;
          }

      }
   
Comments
Member 8233601 23-Aug-12 4:40am
   
thnx a lot..
[no name] 23-Aug-12 7:04am
   
you are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100