Tim,
This is from the documentation for the FontConverter class. It shows
you how to get a converter for the font, as well as get the string for a
particular font:
private void ShowFontStringConversion(PaintEventArgs e)
{
// Create the FontConverter.
System.ComponentModel.TypeConverter converter =
System.ComponentModel.TypeDescriptor.GetConverter(typeof(Font));
Font font1 = (Font) converter.ConvertFromString("Arial, 12pt");
string fontName1 = converter.ConvertToInvariantString(font1);
string fontName2 = converter.ConvertToString(font1);
e.Graphics.DrawString(fontName1, font1, Brushes.Red, 10, 10);
e.Graphics.DrawString(fontName2, font1, Brushes.Blue, 10, 30);
}
To convert from a string to an object, it's easy, just call the
ConvertFromInvariantString (you want to store these, as they are not
locale-specific):
Font f = (Font) fc.ConvertFromInvariantString(s);
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Tim said:
Thank you Nicholas, I don't suppose you have an example do you?
Tim
Nicholas Paldino said:
Tim,
Use the FontConverter class in the System.Drawing namespace. It will
convert a font to a string representation, and back to a Font again, with
the appropriate point size, styles, etc, etc. The output of
FontConverter would be what you store in your database (or construct from
your database, but its easier to just store the value it outputs).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Tim said:
Hi Guys,
I want to build a font like so:
headerFont = new Font("Times New Roman", 10, FontStyle.Underline |
FontStyle.Bold);
It is going to be built dynamically from the DB. How do I build the
styles dynamically. In the above example it has underline and bold, it
could also have italics, or none of them, or a different combination.
How do I build that in code? I guess it is the pipe character which is
throwing me off.
Thanks,
Tim