 |
|
|
|
| Author |
Message |
deerchao
Joined: 23 Nov 2007 Posts: 2
|
Posted: Wed Dec 12, 2007 6:17 am Post subject: gdi+ and line break |
|
|
Hi, I'd like to render colorful text with word wrap on screen (kind of
inline 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!
Archived from group: microsoft>public>dotnet>languages>csharp |
|
| Back to top |
|
 |
Nicholas Paldino [.NET/C#
Joined: 08 Aug 2007 Posts: 71
|
Posted: Wed Dec 12, 2007 5:13 pm Post subject: Re: gdi+ and line break |
|
|
You mentioned that you should avoid creating a lot of objects in the
OnPaint handler. I don't think that this is an issue here. Granted, you
might trigger memory pressure in the OnPaint handler, but simply creating
the objects isn't going to trigger a GC. A GC is going to happen when it
happens. Also, creating all of those strings and not holding references to
them is going to make the cleanup of those strings rather quick (it's not
going to survive past one generation).
Are you using .NET 3.0 by chance? If so, have you considered using WPF?
It will make what you are trying to do much, MUCH easier and it might be
worth the upgrade if you are already using .NET 2.0 (as it is just extra
libraries, no CLR changes).
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"deerchao" wrote in message @s8g2000prg.googlegroups.com...
> Hi, I'd like to render colorful text with word wrap on screen (kind of
> inline 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! |
|
| Back to top |
|
 |
deerchao
Joined: 23 Nov 2007 Posts: 2
|
Posted: Thu Dec 13, 2007 3:57 am Post subject: Re: gdi+ and line break |
|
|
Thanks!
What you said made me feel much better. I'll use the substring way to
break text into lines.
One of my friends showed me how to do this in WPF with TextBlock, it's
dead easy, made me want to kill myself. Anyway, I can't just switch to
WPF from WinForms right now, I'm not ready (know little about WPF),
and I don't think my users are ready, either. May be after one or more
years, I'll turn to WPF.
Thanks again!
On Dec 13, 1:13 am, "Nicholas Paldino [.NET/C# MVP]"
wrote:
> You mentioned that you should avoid creating a lot of objects in the
> OnPaint handler. I don't think that this is an issue here. Granted, you
> might trigger memory pressure in the OnPaint handler, but simply creating
> the objects isn't going to trigger a GC. A GC is going to happen when it
> happens. Also, creating all of those strings and not holding references to
> them is going to make the cleanup of those strings rather quick (it's not
> going to survive past one generation).
>
> Are you using .NET 3.0 by chance? If so, have you considered using WPF?
> It will make what you are trying to do much, MUCH easier and it might be
> worth the upgrade if you are already using .NET 2.0 (as it is just extra
> libraries, no CLR changes).
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - m...@spam.guard.caspershouse.com
>
> "deerchao" wrote in message
>
> @s8g2000prg.googlegroups.com...
>
> > Hi, I'd like to render colorful text with word wrap on screen (kind of
> > inline 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! |
|
| Back to top |
|
 |
Nicholas Paldino [.NET/C#
Joined: 08 Aug 2007 Posts: 71
|
Posted: Fri Dec 14, 2007 2:10 am Post subject: Re: gdi+ and line break |
|
|
Just a piece of advice, you might want to take a look at it sooner than
later. It's easier to learn the basics now and keep up with them as you
move along.
Granted, there is a cost, but if doing what you are doing now was done
so easy in WPF, imagine what other things could be done more easily for you.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"deerchao" wrote in message @b1g2000pra.googlegroups.com...
> Thanks!
>
> What you said made me feel much better. I'll use the substring way to
> break text into lines.
>
> One of my friends showed me how to do this in WPF with TextBlock, it's
> dead easy, made me want to kill myself. Anyway, I can't just switch to
> WPF from WinForms right now, I'm not ready (know little about WPF),
> and I don't think my users are ready, either. May be after one or more
> years, I'll turn to WPF.
>
> Thanks again!
>
> On Dec 13, 1:13 am, "Nicholas Paldino [.NET/C# MVP]"
> wrote:
>> You mentioned that you should avoid creating a lot of objects in the
>> OnPaint handler. I don't think that this is an issue here. Granted, you
>> might trigger memory pressure in the OnPaint handler, but simply creating
>> the objects isn't going to trigger a GC. A GC is going to happen when it
>> happens. Also, creating all of those strings and not holding references
>> to
>> them is going to make the cleanup of those strings rather quick (it's not
>> going to survive past one generation).
>>
>> Are you using .NET 3.0 by chance? If so, have you considered using
>> WPF?
>> It will make what you are trying to do much, MUCH easier and it might be
>> worth the upgrade if you are already using .NET 2.0 (as it is just extra
>> libraries, no CLR changes).
>>
>> --
>> - Nicholas Paldino [.NET/C# MVP]
>> - m...@spam.guard.caspershouse.com
>>
>> "deerchao" wrote in message
>>
>> @s8g2000prg.googlegroups.com...
>>
>> > Hi, I'd like to render colorful text with word wrap on screen (kind of
>> > inline 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!
> |
|
| Back to top |
|
 |
Martin Bonner
Joined: 14 Dec 2007 Posts: 1
|
Posted: Fri Dec 14, 2007 9:14 am Post subject: Re: gdi+ and line break |
|
|
On Dec 12, 9:17 am, deerchao wrote:
> Hi, I'd like to render colorful text with word wrap on screen (kind of
> inline tag to change text color in html), but run into the line
> break problem.
[snip]
> 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.
Can you use a browser control?
(The problem with .Net 3.0 is that it won't run on Win2K - and
certainly our customers won't accept that for several years ... it's
not long since we weaned them off NT4 + Win98)
|
|
| Back to top |
|
 |
|
|
| Related Topics: | web form add a line break to a place holder have a web form with page layout = FlowLayout have a PlaceHolder adding controls to the PlaceHolder e.g. (TextBox1); question how do I had a line break to the PlaceHolder ?
Draw a line Hi, Is there a way to show a line in Mobile.NET? I would like to do so because sometimes we may need to split the main and sub contents. Thanks, Kenny
Extra line in GridView Why am I am getting an extra line in GridView with the following text in the 1st column: Here's partial listing of my code: = priv
CEAPPMGR command line options? Anyone know where they are documented? Google/MSDN search have been =( -b
My Script to run a Command-Line from ASP does not work. Hi, My Script to run a Command-Line from ASP does not work. No errors are returned either. It is on IIS. The directory where the script exists is on Drive I:, The executable .exe is on Drive D: Do you see any problems with the script below? Can you help m |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|