I have solved the problem.
I declared a integer variable at class level-
public static int Form_Count;
And on menu Item click event I modified the above written method as:-
First, it will check if Form_Count is 0, then proceed and do the work and change Form_Count to 1. If Form_Count is 1 then it will show the defined message.
if (Form_Count < 1)
{
foreach (Form form in Application.OpenForms)
{
if (form.GetType() == typeof(form1))
{
form.Activate();
return;
}
}
form1 cr = new form1();
cr.MdiParent = this;
cr.Show();
menuStrip1.Enabled = false;
Form_Count = 1;
}
else
{
NoMessageBox.ShowBox("Can open one form at a time.", "Form");
}
And On the form Close event i.e. I have written on button click,
Menu strip is enabled and Form_Count will be changed to 0 again. In this way:-
frmMain_Page.menustrip.Enabled = true;
frmMain_Page.Form_Count = 0;