Convert From String to Font

  • Thread starter Thread starter Alberto
  • Start date Start date
A

Alberto

I have in the string "font" the value "Tahoma; 18pt; style=Italic" or any
other but when I execute this code, the font of the label is always the same
("Ms sans serif").

Does anybody know why this code doesn't work? Thank you.

System.ComponentModel.TypeConverter converter =
System.ComponentModel.TypeDescriptor.GetConverter(typeof(Font));
lbl.Font = (Font) converter.ConvertFromString(font);
 
Hi Alberto,

Try separate the value by comma and see if the problem still persist or
not.

"Tahoma, 18pt, style=Italic"

Regards.
 
Hi Alberto,

The code should work, and the string produces a Tahome font of 18pt for me
(VS2008).

Are you perhaps executing the code BEFORE the InitializeComponent method? If
not, see if you set the font elsewhere, or recreate the label.
 
Back
Top