How to close all form but not application.exit()
-
hi, i have a main form. it has list view of items that when clicked will open up another form without closing the main form. i did a inactivity timeout where user will be require to login again. if that happen, how do i close all current open form??
Application.OpenForms will return a Forms[] for all open forms. You can for loop through it closing the ones you no longer need (with Form.Close(), obviously). Do not try to foreach loop through, as the Close() may remove it from the array.
If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.
-
You need to keep form objects that are open in a collection. When relogin requires, loop through this list and dispose everything.
Best wishes, Navaneeth
N a v a n e e t h wrote:
loop through this list and dispose closeeverything.
Don't use dispose on a form that is currently displayed - unpredictable things may occur!
If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.
-
Application.OpenForms will return a Forms[] for all open forms. You can for loop through it closing the ones you no longer need (with Form.Close(), obviously). Do not try to foreach loop through, as the Close() may remove it from the array.
If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.
im implementing windows mobile using compact framework so there isn't application.openforms. is there something else similar?
-
N a v a n e e t h wrote:
loop through this list and dispose closeeverything.
Don't use dispose on a form that is currently displayed - unpredictable things may occur!
If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.
When I say dispose everything, I didn't meant to call
Dispose()
method. BTW, how it can cause unpredictable things? :confused:Best wishes, Navaneeth
-
im implementing windows mobile using compact framework so there isn't application.openforms. is there something else similar?
Not unless you create it yourself - keep a copy of the form object when you do the create, chain into the FormClosing event and remove it when it closes. You can then manually Close() each open instance.
If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.
-
When I say dispose everything, I didn't meant to call
Dispose()
method. BTW, how it can cause unpredictable things? :confused:Best wishes, Navaneeth
If the form has a background thread working, it could be using resources that you have disposed.
If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.
-
Not unless you create it yourself - keep a copy of the form object when you do the create, chain into the FormClosing event and remove it when it closes. You can then manually Close() each open instance.
If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.
hi OriginalGriff, what you mean is to create a class which act as a application hub that store all created form instances?? im sorry but wat do u mean by chain into the formClosing event?
-
hi OriginalGriff, what you mean is to create a class which act as a application hub that store all created form instances?? im sorry but wat do u mean by chain into the formClosing event?
Store them as part of your main form, as either an array of Form objects, or as individual YourForm references. At the moment, you do something like
YourForm yf = new YourForm();
yf.Show();when the use clicks one of your list view entries - just move the "YourForm yf" outside the method (and give it a better name). You then change it to
yf = new YourForm();
yf.FormClosing += new EventHandler(YourFormClosing);
yf.Show();and add
private void YourFormClosing(object sender, EventArgs e)
{
yf = null;
}to remove it when it closes. You can then check
if (yf != null)
{
yf.Close();
}If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.
-
hi, i have a main form. it has list view of items that when clicked will open up another form without closing the main form. i did a inactivity timeout where user will be require to login again. if that happen, how do i close all current open form??
You could simply call
Form.Hide()
instead of closing the forms outright..45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
Store them as part of your main form, as either an array of Form objects, or as individual YourForm references. At the moment, you do something like
YourForm yf = new YourForm();
yf.Show();when the use clicks one of your list view entries - just move the "YourForm yf" outside the method (and give it a better name). You then change it to
yf = new YourForm();
yf.FormClosing += new EventHandler(YourFormClosing);
yf.Show();and add
private void YourFormClosing(object sender, EventArgs e)
{
yf = null;
}to remove it when it closes. You can then check
if (yf != null)
{
yf.Close();
}If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.
hmm okay i will go try it out. tks again Original Griff
-
hi, i have a main form. it has list view of items that when clicked will open up another form without closing the main form. i did a inactivity timeout where user will be require to login again. if that happen, how do i close all current open form??