[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

MeasureString - Slighly narrower than actual text.

Phil Jones

12/9/2004 5:00:00 AM

When I use the MeasureString method of the [Graphics] object to determine
the size that a string will take up when rendered - the method returns a
Size that has a width slightly narrower than the actual string.

By this I mean that if I paint the string within the returned size bounds it
falls off the end, or an ellipsus is displayed (if trimming is set
appropriately).

Is this by design?? Is there a standard way to correct this, or what should
I do? At the moment I'm increasing the width by the point-size of the font,
but that seems a bit dodgy to me.

Thanks for any advice...

====
Phil


2 Answers

Bob Powell

12/9/2004 10:13:00 AM

0

When you use MeasureString you must use the same TextRenderingHint in the
Graphics object as you do when you draw it. Even then, the most accurate
method is to measure using TextRenderingHint.Antialias.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Phil Jones" <phil_newsgroup@hotmail.com> wrote in message
news:es3WMoa3EHA.1260@TK2MSFTNGP12.phx.gbl...
> When I use the MeasureString method of the [Graphics] object to determine
> the size that a string will take up when rendered - the method returns a
> Size that has a width slightly narrower than the actual string.
>
> By this I mean that if I paint the string within the returned size bounds
it
> falls off the end, or an ellipsus is displayed (if trimming is set
> appropriately).
>
> Is this by design?? Is there a standard way to correct this, or what
should
> I do? At the moment I'm increasing the width by the point-size of the
font,
> but that seems a bit dodgy to me.
>
> Thanks for any advice...
>
> ====
> Phil
>
>


Phil Jones

12/10/2004 2:27:00 AM

0

Thanks Bob - now that you point it out it makes sense that the
TextRenderingHint would have an effect on size.

Cheers,
===
Phil


"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:ehd0sed3EHA.2592@TK2MSFTNGP09.phx.gbl...
> When you use MeasureString you must use the same TextRenderingHint in the
> Graphics object as you do when you draw it. Even then, the most accurate
> method is to measure using TextRenderingHint.Antialias.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tips...
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/f...
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Phil Jones" <phil_newsgroup@hotmail.com> wrote in message
> news:es3WMoa3EHA.1260@TK2MSFTNGP12.phx.gbl...
>> When I use the MeasureString method of the [Graphics] object to determine
>> the size that a string will take up when rendered - the method returns a
>> Size that has a width slightly narrower than the actual string.
>>
>> By this I mean that if I paint the string within the returned size bounds
> it
>> falls off the end, or an ellipsus is displayed (if trimming is set
>> appropriately).
>>
>> Is this by design?? Is there a standard way to correct this, or what
> should
>> I do? At the moment I'm increasing the width by the point-size of the
> font,
>> but that seems a bit dodgy to me.
>>
>> Thanks for any advice...
>>
>> ====
>> Phil
>>
>>
>
>