I want to use a custom font for my WindowsForm.
For this purpose, I added the font to the program as follows.
And I used the following code to change the font of all the controls.
public void SetFontControls()
{
var privatefontcollection = new PrivateFontCollection();
var fontLength = Properties.Resources.IRANSans.Length;
var fontData = Properties.Resources.IRANSans;
var data = Marshal.AllocCoTaskMem(fontLength);
Marshal.Copy(fontData, 0, data, fontLength);
privatefontcollection.AddMemoryFont(data, fontLength);
Marshal.FreeCoTaskMem(data);
foreach (Control c in Controls)
{
c.Font = new Font(privatefontcollection.Families[0], 12);
}
}
I called this code in the Function load Form.
private void FormHydro_Load(object sender, EventArgs e)
{
SetFontControls();
}
But the problem is that the size changes all Controls but the font does not change.
I tried different fonts but nothing changes.