Convert From String to Font

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

kndg

Hi Alberto,

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

"Tahoma, 18pt, style=Italic"

Regards.
 
M

Morten Wennevik [C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top