Based on Steve's good answer, I would do the following improvements:
/// <summary>
/// Changes fonts of controls contained in font collection recursively. <br/>
/// <b>Usage:</b> <c><br/>
/// SetAllControlsFont(this.Controls, 20); // This makes fonts 20% bigger. <br/>
/// SetAllControlsFont(this.Controls, -4, false); // This makes fonts smaller by 4.</c>
/// </summary>
/// <param name="ctrls">Control collection containing controls</param>
/// <param name="amount">Amount to change: posive value makes it bigger,
/// negative value smaller</param>
/// <param name="amountInPercent">True - grow / shrink in percent,
/// False - grow / shrink absolute</param>
public static void SetAllControlsFontSize(
System.Windows.Forms.Control.ControlCollection ctrls,
int amount = 0, bool amountInPercent = true)
{
if (amount == 0) return;
foreach (Control ctrl in ctrls)
{
// recursive
if (ctrl.Controls != null) SetAllControlsFontSize(ctrl.Controls,
amount, amountInPercent);
if (ctrl != null)
{
float oldSize = (float)ctrl.Font.Size;
float newSize =
(amountInPercent) ? oldSize + oldSize * ((float)amount / (float)100)
: oldSize + (float)amount;
if (newSize < 4) newSize = 4; // don't allow less than 4
var fontFamilyName = ctrl.Font.FontFamily.Name;
ctrl.Font = new Font(fontFamilyName, newSize);
};
};
}
This allows to grow or shrink the font size in percent like:
SetAllControlsFontSize(this.Controls, 20);
Or you can shrink the font size absolutely by a value of -4 like:
SetAllControlsFontSize(this.Controls, amount: -4, amountInPercent: false);
In both examples, all fonts will be affected by the change. You do not need to know the font family names, each control can have different ones.
Combined with this answer you can auto-scale fonts in your application based on Windows settings (which you can find if you right click on the desktop, then select Display settings, Scale and layout and modify the value "Change the size of text, apps, and other items" - in Windows 10 versions newer than build 1809 this is (re-)named as "Make everything bigger"):
var percentage = GetWindowsScaling() - 100;
SetAllControlsFontSize(this.Controls, percentage);
You should also limit the size to a certain maximum/minimum, based on your forms layout, e.g.
if (percentage > 80) percentage = 80;
if (percentage < -20) percentage = -20;
Likewise this is true for absolute values - note that in the code there is already a limit set: Practically, a font cannot be smaller than 4 em - this is set as minimum limit (of course you can adapt that to your needs).