Derived Forms resizing in dotnet. (Fix)
Problem:
If you have a form base class:
public frmBase : System.Windows.Forms
{
public frmBase {
// DefaultFormFont is new Font("Tahoma", 10);
this.font = SomeOtherClassFullofConstants.DefaultFormFont;
}
....
}
But the designer shows the font as MS Sans Serif, 8.25ft (The default
value).
Then you create a derived form
public class frmDerived : frmBase { }
But in the designer, you choose the font to be Tahoma 10.
Unexpected:
On each subsequent build, the frmDerived form will grow in size
linearly, that includes bigger controls, larger form size, and greater
spacing. It only takes 5 or 6 builds before things get very large. But
only if it is open in the designer view (I think, not sure).
Unexpected#2:
If you change
public class frmDerived : frmBase { }
to
public class frmDerived : Forms { }
Then it will shrink back, but only if it just enlarged, very funky.
Solution
Make the font the same in the designer of both frmBase and frmDerived.
That means remove it from the constructor.
From some other Google messages, it also looks like you should do:
using SomeNameSpace.Base;
//…
public class frmDerived : frmBase
and NOT
// BADC0DE
public class frmDerived : SomeNameSpace.Base.frmBase
// BADC0DE
Not sure why, looks like voodoo, but it could be worse...
--
Tony
Stratton
P.S. This took me awhile to figure out, hopefully you can benefit from
my time. Well, my companies time...
P.P.S (..."bigger" controls, "larger" form size, and "greater"...) I
used three synonyms to enhance Google search-ability. I wish that the
MotherShip (MS) would do this with their MSDN search.