I am using this function to close existing form and open a new form.
If there is no exixting form, it throws error.
Error :
Target : System.Object
if (ApplicationFormStatus.CheckIfFormIsOpen("FormName"))
{
// It means it exists, so close the form
}
public bool CheckIfFormIsOpen(string formname)
{
//FormCollection fc = Application.OpenForms;
//foreach (Form frm in fc)
//{
// if (frm.Name == formname)
// {
// return true;
// }
//}
//return false;
bool formOpen= Application.OpenForms.Cast
I have pasted the two methods one simple one and the second one is the LINQ.