I have these classes :
internal partial class FBase : Form
{
public FBase() { InitializeComponent(); }
public FBase(bool owner) : this()
{
if (!owner) { this.Opacity = 0; Load += (s, e) => Close(); }
}
}
internal partial class Form1 : FBase
{
public Form1(bool owner) : base(owner) { InitializeComponent(); }
}
This code works (does not show Form1):
Form1 f = new Form1(false);
if(f != null) { f.MdiParent = parent; f.Show(); }
But this does not work (shows Form1):
OpenSingleMdiChild(() => new Form1(false));
This is the implementation of OpenSingleMdiChild:
public static void OpenSingleMdiChild<T>(this Form parent, Func<T> factory) where T : Form
{
T f = null;
foreach (Form c in parent.MdiChildren) if (c.GetType() == typeof(T)) { f = c; break; }
if (f == null) { f = factory(); f.MdiParent = parent; }
f.Show(); f.Select();
}