PC Review


Reply
Thread Tools Rate Thread

Cannot get MeasureString to return accurate value for making columns

 
 
Audrey Homer
Guest
Posts: n/a
 
      27th Aug 2003
Hi all. I realize this MeasureString topic has been
tossed around quite a bit but I can't seem to make it work
well despite trying out all the postings. I implemented
all I tried in the little function at the end of this
posting.

I've been trying to create some text separated into
columns by spaces. (I can't use tabs to make these spaces
between columns because this text ultimately goes on a
device that doesn't support tabs.) Basically what i do is

1. get the cells contents and put it into the output text
2. keep adding spaces to the text until it reaches the
column size
3. do the same for all the columns in the cells and for
each row.

Unfortunately even though MeasureString says the distance
between the first and second column is nearly the same for
all rows, it always looks like this:


first_column second_column
stuff1 455.445
otherstuff2 593.558
morestuff3 89.88

According to MeasureString the distance between the first
and second column are minimal for each row but to the eye
its quite large. Can anyone explain this is or point me
in the right direction? Thank you!

public static float GetStringWidth(string text,Font f)
{
StringFormat format= (StringFormat)
StringFormat.GenericTypographic.Clone();
format.FormatFlags=StringFormatFlags.MeasureTrailingSpaces
| StringFormatFlags.NoClip
| StringFormatFlags.NoWrap
|
StringFormatFlags.DisplayFormatControl
| StringFormatFlags.NoFontFallback;
format.Trimming=StringTrimming.None;

System.Windows.Forms.Control myControl = new
System.Windows.Forms.Control();
Graphics TempGraphic = myControl.CreateGraphics();
TempGraphic.TextRenderingHint =
TextRenderingHint.AntiAlias;
float StringSize = TempGraphic.MeasureString
(text,f,0xffff,format).Width;
TempGraphic.Dispose();
TempGraphic = null;
myControl.Dispose();
myControl = null;
return StringSize;
}

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making existing columns into look-up columns Krende Microsoft Access 3 4th Jun 2009 04:01 PM
Making a accurate Template Dave Microsoft Word Document Management 5 28th Jan 2008 04:35 PM
MeasureString(string s,Font font) dosen't return right pixels =?Utf-8?B?a2VpdGg=?= Microsoft C# .NET 2 16th May 2006 04:18 PM
Re: Making a Lookup function return a Zero Chip Pearson Microsoft Excel Worksheet Functions 0 12th Feb 2004 04:42 PM
If it returns #N/A, making it return 0 jayhawk1919 Microsoft Excel Misc 5 9th Nov 2003 10:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:15 PM.