Change Font of a Form Dynamically

  • Thread starter Thread starter Jack Wright
  • Start date Start date
J

Jack Wright

Dear All,
Is there a way where we can change the size of the font in a Form
dynamically and also all the controls in the form? Can the Form be
resized and Layout changed to suite the changes?
Has someone worked on such a requirement before?

Please help

TALIA
Many Regards
Jack
 
Hi, Jack

if you can change font for the control dynamically, you should have no
problem to change it for the form and its controls too. Some controls might
not allow it, however, so you might need to check if you use such.

HTH
Alex
 
Hi Alex,
Thanks for your reply...
Is there a sample or a third party utitily that does this
"Autoresize a form and its controls when the user changes the font"
I burned my hands doing the following:

FontDialog fontDialog1 = new FontDialog();
fontDialog1.ShowColor = true;

if(fontDialog1.ShowDialog() != DialogResult.Cancel )
{
lblName.Font = fontDialog1.Font
}
Graphics g = new Graphics( );
SizeF dimensions = g.MeasureString(lblName.Text, fontDialog1.Font)
lblName.Width = Unit.Pixel(30 + (int)dimensions.Width);

The alignment goes for a toss...

Please help...

TALIA
Many Regards
Jack
 
Hi, Jack

First, you might want to use Graphics.MeasureCharacterRanges, which as some
say provides more precise metrics.
Second, you might want to use AutoSize property for some of controls and
Dock and Anchor styles for form controls.
And third, I would use SystemInformation metrics for most of elements - you
should not forget about system-wide settings, which could be changed by
user - if you resize / reposition them manually.
Last one - maybe you should consider subclassing base control to provide
basic autoresizing functionality you want?
I don't think you will find complete implementation of autoresize
functionality (?). It's so control-dependent that I personally do not think
it is worth the effort.

HTH
Alex
 
Back
Top