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"
Thanks
For more simplicity you may create a public static bool variable which will tell whether the form is opened or not. On form load event assign 'true' and on closed event assign 'false' value. Show activity on this post. Show activity on this post.
void Click() { var tempFrm = new dialogForm(); tempFrm. Load += frmLoad; tempFrm. Show(); } void frmLoad(object s, EventArgs ea) { // form loaded continue your code here! }
When we need to exit or close opened form then we should use "this. Close( )" method to close the form on some button click event. When we are running a winform application & need to exit or close SUB APPLICATION or CURRENT THREAD then we should use "System.
To cancel the closure of a form, set the Cancel property of the CancelEventArgs passed to your event handler to true .
maybe this helps:
FormCollection fc = Application.OpenForms; foreach (Form frm in fc) { //iterate through if (frm.Name == "YourFormName") { bFormNameOpen = true; } }
Some code in the foreach to detect the specific form and it could be done. Untested though.
Found on http://bytes.com/topic/c-sharp/answers/591308-iterating-all-open-forms
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With