Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2007

Tip: Looking for answers? Try searching our database.

Measuring the exact size of a string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
EgregioSignore - 29 Oct 2007 13:46 GMT
Hi all,

I want to write a function that gets the following parameters:

a string "s"
a font "f"

and returns the EXACT width and height of the font.

I tried first with MeasureString but it adds me extra space;
then I tried with MeasureCharacterRanges but I didn't manage
to get rid of an extra space.

I need to have a pair of values that could enable me to draw,
let's say, a bounding box that TOUCHES the string on every border,
no matter how the glyphs are shaped (f.ex. a string with only
a period, ".", should return a very small b.box instead of taking
account of the extra space OVER the dot).

Thanks for your help!
Chris Nahr - 29 Oct 2007 14:19 GMT
Text measurements always include spacing pixels all around, as
determined by the font.  AFAIK the only reliable way to determine the
actual pixels occupied by a text string is to render it to a memory
device, then scan from each side until you see a non-white pixel.
--
http://www.kynosarges.de
MarPrag - 29 Oct 2007 15:21 GMT
Chris Nahr ha scritto:
> Text measurements always include spacing pixels all around, as
> determined by the font.  AFAIK the only reliable way to determine the
> actual pixels occupied by a text string is to render it to a memory
> device, then scan from each side until you see a non-white pixel.

Yes, I had already figured out this technique, but I hoped
to avoid it as it seems so unelegant ... Thanks, anyway!

MarPrag aka EgregioSignore

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.