From: kndg on
On 6/17/2010 12:16 AM, Tony Johansson wrote:
> "kndg"<reply(a)this.newsgroup> skrev i meddelandet
> news:hva5h7$92s$1(a)news.eternal-september.org...
>> On 6/16/2010 4:59 PM, Tony Johansson wrote:
>>> [...]
>>> // 3 FontConverter converter = new FontConverter();
>>> // 3 Font f = (Font)converter.ConvertFromString("Arial, 12pt,
>>> FontStyle.Bold");
>>
>> You are using incorrect format for the converter to parse. It should be
>> formatted as:
>>
>> Font f = (Font)converter.ConvertFromString("Arial, 12pt, style=Bold");
>
> No you example doesn't give correct font because it's very different from
> code marked with 1 and 2
>
> //Tony
>

Hi Tony,

private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Font font1 = new Font("Arial", 12, FontStyle.Bold);

FontFamily ff = new FontFamily("Arial");
Font font2 = new Font(ff, 12, FontStyle.Bold);

FontConverter converter = new FontConverter();
Font font3 = (Font)converter.ConvertFromString("Arial, 12pt,
style=Bold");

g.DrawString("Hello, World!", font1, Brushes.Blue, 10, 10);
g.DrawString("Hello, World!", font2, Brushes.Blue, 10, 30);
g.DrawString("Hello, World!", font3, Brushes.Blue, 10, 50);

MessageBox.Show(String.Format("font1 == font2 : {0}",
font1.Equals(font2)));
MessageBox.Show(String.Format("font1 == font3 : {0}",
font1.Equals(font3)));
MessageBox.Show(String.Format("font2 == font3 : {0}",
font2.Equals(font3)));
}

All would print the same and the result of equality is all true.

Please note that, the converter is sensitive to culture information and
if your current culture is other than english, you should translate the
comma (',') character to the equivalance character of your culture.

Regards.
From: Jeff Johnson on
"kndg" <reply(a)this.newsgroup> wrote in message
news:hvbqmf$6q5$1(a)news.eternal-september.org...

> Please note that, the converter is sensitive to culture information and if
> your current culture is other than english, you should translate the comma
> (',') character to the equivalance character of your culture.

The easiest thing to do is to create the desired font "normally" and then
use FontConverter.ConvertToString() to see what the output is. The input to
ConvertFromString() should look exactly the same.


From: kndg on
On 6/17/2010 9:56 PM, Jeff Johnson wrote:
> "kndg"<reply(a)this.newsgroup> wrote in message
> news:hvbqmf$6q5$1(a)news.eternal-september.org...
>
>> Please note that, the converter is sensitive to culture information and if
>> your current culture is other than english, you should translate the comma
>> (',') character to the equivalance character of your culture.
>
> The easiest thing to do is to create the desired font "normally" and then
> use FontConverter.ConvertToString() to see what the output is. The input to
> ConvertFromString() should look exactly the same.
>

Yes, and I found that some countries in Europe use semicolon (';')
instead of comma (','). That's probably the source of Tony's error. Or,
he could use ConvertFromInvariantString() to instruct the converter to
parse using invariant culture.

Regards.