چند روش واسه این کار هست
یکی توسط Generic Singleton
public class SingletonProvider<T> where T : new()
{
SingletonProvider() { }
public static T Instance
{
get
{
return SingletonCreator.Instance;
}
}
class SingletonCreator
{
static SingletonCreator(){}
private static T instance;
public static T Instance
{
get
{
System.Windows.Forms.Form frm = instance as System.Windows.Forms.Form;
if (instance == null || frm.IsDisposed==true)
instance = new T();
return instance;
}
}
}
}
طرز استفاده اش هم بصورت :
Form2 f2 = SingletonProvider<Form2>.Instance;
f2.Show();
یه روش دیگه استفاده از Application :
Form f2;
if (Application.OpenForms["Form2"] != null)
f2 = Application.OpenForms["Form2"];
else
f2 = new Form2();
f2.Show();
بازم هست ولی فکر کنم همینا کارتو راه بندازه!!