0
我一直在使用工廠模型來創建子窗體添加到MDI窗體。這是我一直在使用的代碼:C#中的工廠模型,而不使用默認的構造函數
/// <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());
}
}
}
然而,情況已經出現了,我有一個整數參數添加到特定形式的構造函數。我怎樣才能改變這一點,並使其反映出來,同時仍然保持目前易用性(或接近)的模式。