FontSize is a float and FontStyle is an enum. Thus it would need to be:
float fsize = float.Parse(...);
new Font(fname, fsize, GetFontStyle(myValue));
Getting a float is easy enough... getting the font style can be a bit more sticky. If you have a string value which represents, say, "Italic" or "Bold", you can use a stupid-simple EnumUtils method like below to get the enum value:
private FontStyle GetFontStyle(string input)
{
return EnumUtils.Parse<FontStyle>("myValue");
}
public static class EnumUtils
{
public static T Parse<T>(string input) where T : struct
{
//since we cant do a generic type constraint
if (!typeof(T).IsEnum)
{
throw new ArgumentException("Generic Type 'T' must be an Enum");
}
if (!string.IsNullOrEmpty(input))
{
if (Enum.GetNames(typeof(T)).Any(
e => e.Trim().ToUpperInvariant() == input.Trim().ToUpperInvariant()))
{
return (T)Enum.Parse(typeof(T), input, true);
}
}
throw new Exception("Could not parse enum");
}
}
If not, it will be harder. But ultimately, you do need to find a way to convert whatever you've got into this:
Regular Normal text.
Bold Bold text.
Italic Italic text.
Underline Underlined text.
Strikeout Text with a line through the middle.
FontStyle is a bit flag, so values can be combined like so:
FontStyle myStyle = FontStyle.Bold | FontStyle.Italic;
This aspect makes the parsing issue sticker.