单件模式的基Form,两个继承它的窗口,实例化时一个窗口,另一个窗口无法实例化了。
namespace CustomForm
{
public partial class BaseForm : DockContent //基窗口 使用了http://sourceforge.net/projects/dockpanelsuite/ 控件
{
private static BaseForm instance = null;
protected override bool ProcessDialogKey(Keys keyData)
{
if ((ActiveControl is TextBox || ActiveControl is ComboBox) &&
keyData == Keys.Enter)
{
keyData = Keys.Tab;
}
return base.ProcessDialogKey(keyData);
}
public BaseForm()
{
InitializeComponent();
}
public static BaseForm Instance(Form fm1, Type FormType, DockPanel dockpanel,bool dialog)
{
if (instance == null)
{
instance = (BaseForm)System.Activator.CreateInstance(FormType);
instance.MdiParent = fm1;
if (dialog == true)
instance.ShowDialog();
else
instance.Show(dockpanel);
return instance;
}
&