471,348 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

wpf/c#: convert string to fontweight

How can I convert a string to a FontFamily?

Suto code:
String sFont = "Bold";
FontFamily ff = (FontFamily)sFont;

Thanks.

--
mo*******@newsgroup.nospam
Jul 15 '08 #1
2 11101
Sorry, I got tottaly messed up on the sample code in the first post.

it should be:
Suto code:
string sWeight = "Bold";
FontWeight fw = (FontWeight)sWeight;

Thanks.
"moondaddy" <mo*******@newsgroup.nospamwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
How can I convert a string to a FontFamily?

Suto code:
String sFont = "Bold";
FontFamily ff = (FontFamily)sFont;

Thanks.

--
mo*******@newsgroup.nospam

Jul 15 '08 #2
Hi,

to convert a type of String to a type of FontWeight there's a class called
FontWeightConverter.
Here's the code for your example:

string sWeight = "Bold";
FontWeight fw = (FontWeight)new
FontWeightConverter().ConvertFromString(sWeight);

I hope it helps.

Regards,
Denis

"moondaddy" <mo*******@newsgroup.nospamschrieb im Newsbeitrag
news:Of**************@TK2MSFTNGP03.phx.gbl...
Sorry, I got tottaly messed up on the sample code in the first post.

it should be:
Suto code:
string sWeight = "Bold";
FontWeight fw = (FontWeight)sWeight;

Thanks.
"moondaddy" <mo*******@newsgroup.nospamwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>How can I convert a string to a FontFamily?

Suto code:
String sFont = "Bold";
FontFamily ff = (FontFamily)sFont;

Thanks.

--
mo*******@newsgroup.nospam

Jul 15 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Alain | last post: by
6 posts views Thread by Alex | last post: by
3 posts views Thread by Convert TextBox.Text to Int32 Problem | last post: by
7 posts views Thread by patang | last post: by
6 posts views Thread by patang | last post: by
4 posts views Thread by tshad | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.