views:

69

answers:

2

Hi All,

I have the following string in a file, and it needs to be converted back to a Font object. But I'm not sure how to do this one:

font string:

[Font: Name=Segoe UI, Size=14, Units=3, GdiCharSet=1, GdiVerticalFont=False]

I appreciate any help at all, thank you

bael

+2  A: 

Check out my FontBuilder class in the CC.Utilities library. It does exactly what you want and provides an extension method ToStringEx() to cover the FontStyle property that Font.ToString() is missing.

I originally wrote it so I could store a Font in the registry

Edit: Here are the specific files it you're not interested in the whole thing:

FontBuilder: http://ccutilities.codeplex.com/SourceControl/changeset/view/40596#648008 FontExtensions: http://ccutilities.codeplex.com/SourceControl/changeset/view/40596#664902

Cory Charlton
Works perfectly... That's some great work you got there, congrats! :)
baeltazor
+1  A: 

There are various Font constructors, this one appears to fit the bill:

Font Constructor (String, Single, FontStyle, GraphicsUnit, Byte, Boolean)

Initializes a new Font using the specified size, style, unit, and character set.

Parameters

familyName
Type: System.String
A string representation of the FontFamily for the new Font.

emSize
Type: System.Single
The em-size of the new font in the units specified by the unit parameter.

style
Type: System.Drawing.FontStyle
The FontStyle of the new font.

unit
Type: System.Drawing.GraphicsUnit
The GraphicsUnit of the new font.

gdiCharSet
Type: System.Byte
A Byte that specifies a GDI character set to use for this font.

gdiVerticalFont
Type: System.Boolean
A Boolean value indicating whether the new Font is derived from a GDI vertical font.

Unless I've misread your string of course.

You would need to parse the string to pass the appropriate values to the constructor.

ChrisF
You did misunderstand, but that's probably my falt. (haven't slept yet :( )
baeltazor