Search code examples
c#fileiowindows-forms-designer

Dynamically change font of a label in windows forms


I saved the font of a label in a file named file.txt and every time the program runs, i read the file.txt and the font. actually i want to change label's font by coding. saving font :

            string[] t = new string[2];
            t[0] = label1.Font.Name.ToString();
            t[1] = label1.Font.Size.ToString();

            File.WriteAllLines(@"file.txt", t);

reading font :

                label1.Font = new Font(t[0], (float)(int.Parse(t[1])));

but it doesn't work !


Solution

  • two things is important ,check that the font is installed on system and check that the name of the font is written correctly.

    enter image description here