How to prevent from open the same form
-
hi, if i have already open form1, how do i check and not open form1 again??
-
hi, if i have already open form1, how do i check and not open form1 again??
-
hi, if i have already open form1, how do i check and not open form1 again??
assume if you are checking the form "form1", code is below.
public static Form IsFormAlreadyOpen(Type FormType)
{
foreach (Form OpenForm in Application.OpenForms)
{
if (OpenForm.GetType() == FormType)
return OpenForm;
}
return null;
}private void button1\_Click(object sender, EventArgs e) { Form frmTest; if ((frmTest = IsFormAlreadyOpen(typeof(Form1))) == null) { frmTest = new Form1(); frmTest.Show(); } else { frmTest.WindowState = FormWindowState.Normal; frmTest.BringToFront(); } }
this code opens the form if it's not already open otherwise it'll make active form. thatraja
-
assume if you are checking the form "form1", code is below.
public static Form IsFormAlreadyOpen(Type FormType)
{
foreach (Form OpenForm in Application.OpenForms)
{
if (OpenForm.GetType() == FormType)
return OpenForm;
}
return null;
}private void button1\_Click(object sender, EventArgs e) { Form frmTest; if ((frmTest = IsFormAlreadyOpen(typeof(Form1))) == null) { frmTest = new Form1(); frmTest.Show(); } else { frmTest.WindowState = FormWindowState.Normal; frmTest.BringToFront(); } }
this code opens the form if it's not already open otherwise it'll make active form. thatraja
hi thatraja, tks. erm i forgot to mention that i was doing it for windows mobile =). so Application.OpenForms is not available
-
hi thatraja, tks. erm i forgot to mention that i was doing it for windows mobile =). so Application.OpenForms is not available
If this is the same App we talked about yesterday, the list you created to show which forms need to be closed would also double up as a list of open forms wouldn't it? If it needs to be closed at log off, it's open...
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.