我一直在使用工厂模型来创建子表单以添加到 MDI 表单。这是我一直在使用的代码:
/// <summary>
/// This uses the Factory Model to create the child node and then add it to the MDI Parent (this)
/// </summary>
/// <param name="childName">String class name of the child, i.e. RentalEase.PropertyGrid must extend Form or SingleInstance</param>
/// <param name="singleInstance">bool If this class is to be a single instance and restricted to only on instance. Must extend SingleInstance</param>
public void createChild(string childName, bool singleInstance) {
if (singleInstance) {
try {
BaseAndSingleInstanceForm f = BaseAndSingleInstanceForm.getInstanceByType(this, Type.GetType(childName));
f.MdiParent = this;
f.Show();
f.BringToFront();
this.Refresh();
} catch (Exception ex) {
MessageBox.Show("Could not create child: " + ex.ToString());
}
} else {
try {
object o = Activator.CreateInstance(Type.GetType(childName));
if (o is Form) {
Form f = (Form)o;
f.MdiParent = this;
f.Show();
f.BringToFront();
this.Refresh();
} else {
throw new ArgumentException("Invalid Class");
}
} catch (Exception ex) {
MessageBox.Show("Could not create child: " + ex.ToString());
}
}
}
但是,出现了一种情况,我必须将整数参数添加到特定表单的构造函数中。我怎样才能改变它并让它反映它,同时仍然保持模式在它当前的易用性(或几乎)。