Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Close the windows form if its instance is running.

I have three forms
1) Normal Windows Forms (Named Main Screen)
2) MDI form (Named POS)
3) MDI form (Named Stock)

When I click Button on [Main Screen]

I am opening a MDIPOS FORM from [Main Screen] by button click event. The code is:

MIDL
MDIPOS pos=new MDIPOS();
pos.MdiParent = this;
pos.Activate();           
pos.Show();


Getting Problem in Closing the form.
When I close the MDI Form or Main Screen Form
one its instance remain running.
I used :
frmMain.Dispose();  //or
frmMain.Close();


Then also it instance remain running.
If I use only one form, it closes perfectly.

How to close the instance of another form.
because, to access a form, we need to create a new object of that form and that that new object is destroyed , but what about the previous one which was opened.

I hope I explain the problem nicely.

Appreciate your best reply

Thanking You
Posted

1 solution

Try it,

use this in your Close Button (or) Form Closing Event
foreach(Form f in this.MdiChildren)
{
f.Close();
}
 
Share this answer
 

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