juliodiz
asked on
Form open more than 1 time c#
Hello. So i have a problem that my form more than 1 time.
How can i check if the form is open and if it opened i show?
How can i check if the form is open and if it opened i show?
If you are talking about the application in whole (main form) the following may help:
http://codebetter.com/blogs/paul.laudeman/archive/2004/07/17/Windows-Forms-Tip_3A00_-Ensure-only-one-instance-of-your-application-is-running-at-a-time.aspx
However, if you are talking about one of "secondary" forms, i.e. forms you are opening from your application, you may just check a reference to a form. You have to have an only variable to reference the form. If it is nothing - you create and open a new form. If not - show existing form.
http://codebetter.com/blogs/paul.laudeman/archive/2004/07/17/Windows-Forms-Tip_3A00_-Ensure-only-one-instance-of-your-application-is-running-at-a-time.aspx
However, if you are talking about one of "secondary" forms, i.e. forms you are opening from your application, you may just check a reference to a form. You have to have an only variable to reference the form. If it is nothing - you create and open a new form. If not - show existing form.
ASKER
This?
public static void OpenForm(Type frmType)
{
bool bolCtl = false;
foreach (Form form in Application.OpenForms)
{
if (form.GetType().Equals(frm Type))
{
form.Show();
bolCtl = true;
break;
}
}
if (!bolCtl)
{
Form frm = (Form)Activator.CreateInst ance(frmTy pe);
frm.Show();
}
}
public static void LoadForm1()
{
OpenForm(typeof(Login));
//Login _form1 = new Login();
//_form1.Show();
}
public static void OpenForm(Type frmType)
{
bool bolCtl = false;
foreach (Form form in Application.OpenForms)
{
if (form.GetType().Equals(frm
{
form.Show();
bolCtl = true;
break;
}
}
if (!bolCtl)
{
Form frm = (Form)Activator.CreateInst
frm.Show();
}
}
public static void LoadForm1()
{
OpenForm(typeof(Login));
//Login _form1 = new Login();
//_form1.Show();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
Yes above both experts are right.
Yes above both experts are right.
http://dotnetperls.com/single-instance-windows-form
http://www.megasolutions.net/cSharp/Single-Instance-Form-16441.aspx
Or google for Single Instance form in c#