C# – Font properties


I have a text file with the following info in it, on a single line:


(-16777216 is the color of the text in ARGB format).. How would I be able to set this text as the font properties for a label at runtime? I have googled this but couldn't find anything related specifically to my problem. Can anyone please offer any suggestions/help?

thanks lots 🙂

Best Solution

Assuming all four lines are always there...

var fontSettings = System.IO.File.ReadAllLines("fontsettings.txt");

int color = int.Parse(fontSettings[0], System.Globalization.NumberStyles.Any);
string family = fontSettings[1];
float size = float.Parse(fontSettings[2], System.Globalization.CultureInfo.InvariantCulture);
FontStyle style = (FontStyle)Enum.Parse(typeof(FontStyle), fontSettings[3]);

label1.ForeColor = Color.FromArgb(color);
label1.Font = new Font(family, size, style);