jay_t55
jay_t55

Reputation: 11652

Font properties

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

-16777216
Arial
7.8
Bold

(-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 :) jase

Upvotes: 1

Views: 441

Answers (1)

Kawa
Kawa

Reputation: 1488

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);

Upvotes: 2

Related Questions