我有这门课(取自网络):
class SingletonFormProvider
{
static Dictionary<Type, Form> mTypeFormLookup = new Dictionary<Type, Form>();
static public T GetInstance<T>(Form owner)
where T : Form
{
return GetInstance<T>(owner, null);
}
static public T GetInstance<T>(Form owner, params object[] args)
where T : Form
{
if (!mTypeFormLookup.ContainsKey(typeof(T)))
{
Form f = (Form)Activator.CreateInstance(typeof(T), args);
mTypeFormLookup.Add(typeof(T), f);
f.Owner = owner;
f.FormClosed += new FormClosedEventHandler(remover);
}
return (T)mTypeFormLookup[typeof(T)];
}
static void remover(object sender, FormClosedEventArgs e)
{
Form f = sender as Form;
if (f == null) return;
f.FormClosed -= new FormClosedEventHandler(remover);
mTypeFormLookup.Remove(f.GetType());
}
}
如果使用标准打开,我知道如何传递参数:
Form f = new NewForm(parameter); f.Show();
但我正在使用这种打开新表单的方式(在上述课程的帮助下):
var f = SingletonFormProvider.GetInstance<NewForm>(this); f.Show();
那么,如何通过这种打开新表单的方式传递参数呢?
请帮忙。
谢谢。