By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,997 Members | 1,470 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,997 IT Pros & Developers. It's quick & easy.

Convert string to font

P: n/a
Wim
I would like to store the ListView font in the XML config file. So I have
a string variable listFont that stores the font (font.ToString()). It
must be a string variable because a Font object cannot be written to the
XML config file. Next time the program is started the font is read from
the config file. But how to convert the string to a Font object?

--
Wim
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Wm,

"Wim" <wi*@nospam.invalid> wrote in message
news:Xn******************************@213.51.144.3 6...
I would like to store the ListView font in the XML config file. So I have
a string variable listFont that stores the font (font.ToString()). It
must be a string variable because a Font object cannot be written to the
XML config file. Next time the program is started the font is read from
the config file. But how to convert the string to a Font object?


An example of converting a font to/from a string:

...
FontDialog fd = new FontDialog();

if(fd.ShowDialog() != DialogResult.Cancel )
{
Font font = fd.Font;
Console.WriteLine("Font: {0}", font.ToString());

TypeConverter tc = TypeDescriptor.GetConverter(typeof(Font));
string fontString = tc.ConvertToString(font);
Console.WriteLine("Font as string: {0}", fontString);

Font newFont = (Font)tc.ConvertFromString(fontString);
Console.WriteLine("Font: {0}", newFont.ToString());
}
...

Regards,
Dan
Nov 15 '05 #2

P: n/a
Why you don't save the Font propriety?

If you use the following constructor, save the familyName and the emSize in
the config file.

Font.Font(string familyName,float emSize)

"Wim" <wi*@nospam.invalid> schrieb im Newsbeitrag
news:Xn******************************@213.51.144.3 6...
I would like to store the ListView font in the XML config file. So I have
a string variable listFont that stores the font (font.ToString()). It
must be a string variable because a Font object cannot be written to the
XML config file. Next time the program is started the font is read from
the config file. But how to convert the string to a Font object?

--
Wim

Nov 15 '05 #3

P: n/a
Wim
Daniel Pratt wrote:
An example of converting a font to/from a string:


Cool! Works great. Thank you very much.

--
Wim
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.