Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

Make your variable as static

C#
public static ShopMaster shopmaster=null;


then write the code in FormClosing event of your ShopMaster

C#
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;
          }

      }
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900