D
deerchao
Hi, I'd like to render colorful text with word wrap on screen (kind of
inline <font> tag to change text color in html), but run into the line
break problem.
Graphics provides several DrawString methods with line break features,
but I can't make them draw different colors within one string, And if
I split the string into several part, so I can specify their colors,
line breaking won't work.
So, I have to break my string to lines before I pass it/them to
DrawString. This is something I don't know (yet) how to do efficiently
in c#.
I can create many sub strings (with length 1, 2, 3, ...) to
MeasureString them, but this leads to lots of gabage objects, which I
think I should avoid in a OnPaint event handler;
And I can use MeasureCharacterRanges to every chars in the string, so
I will have every char's width. but I found I can only process 32
chars a time because if I passed more CharacterRanges to
StringFormat.SetMeasurableCharacterRanges, there would be an
OverflowException. Since there is a limit number, I think this may be
more unefficient than making lots of strings.
I think there should be a way to do this, though I havn't found it
right now. I looked around for a HTML renderer example, but none of
them is done in C# or .net without a Browser control.
Any help is appreciated, Thanks!
inline <font> tag to change text color in html), but run into the line
break problem.
Graphics provides several DrawString methods with line break features,
but I can't make them draw different colors within one string, And if
I split the string into several part, so I can specify their colors,
line breaking won't work.
So, I have to break my string to lines before I pass it/them to
DrawString. This is something I don't know (yet) how to do efficiently
in c#.
I can create many sub strings (with length 1, 2, 3, ...) to
MeasureString them, but this leads to lots of gabage objects, which I
think I should avoid in a OnPaint event handler;
And I can use MeasureCharacterRanges to every chars in the string, so
I will have every char's width. but I found I can only process 32
chars a time because if I passed more CharacterRanges to
StringFormat.SetMeasurableCharacterRanges, there would be an
OverflowException. Since there is a limit number, I think this may be
more unefficient than making lots of strings.
I think there should be a way to do this, though I havn't found it
right now. I looked around for a HTML renderer example, but none of
them is done in C# or .net without a Browser control.
Any help is appreciated, Thanks!