I have a form "fm" that is a simple info window that opens every 10 mins (fm.Show();
).
How I can make that every 10 mins it will check if the form "fm" is open and if it is open it closes it and open it again!
Now the form fm is always created with form fm = new form();
so when I try to check if the form is open it will always be false and open a new window even if there is one form before!
I need to have a tool to give it a unique identity and then check if this form with unique identity is opened or not!
I do not want to just update the data on the form (fm), because I have a complicated info with buttons.
The form name is "UpdateWindow"
Solved using the following:
Form fc = Application.OpenForms["UpdateWindow"];
if (fc != null)
fc.Close();
fc.Show();
where
Form1
is the name of your form.Funny, I had to add to this thread.
1) Add a global var on form.show() and clear out the var on form.close()
2) On the parent form add a timer. Keep the child form open and update your data every 10 min.
3) put timer on the child form to go update data on itself.
Try this, it will work :
In my app I had a mainmenu form that had buttons to navigate to an assortment of other forms (aka sub-forms). I wanted only one instance of each sub-form to be running at a time. Plus I wanted to ensure if a user attempted to launch a sub-form already in existence, that the sub-form would be forced to show "front¢er" if minimized or behind other app windows. Using the currently most upvoted answers, I refactored their answers into this:
I know I am late... But for those who are curious... This is another way
In addition, may be this will help