I have the exact string : 123..
I want to see what its length would be as if it was on a Html page ( as SPAN)
font-name:arial
font-size:16px;
I made an experiment :
http://jsbin.com/axezib/edit#preview
so
<span style="font-family:arial;border:solid 1px red;display:inline-block;font-size:16px;">123..</span>
is rendered to :

and its properties :
ofcourse *
{
padding:0px;margin:0px;
}

as you can see its width is 35 and height=19. ( lets ignore the border …)
however I have this code which should (or not) tell me the same result :
void Main( )
{
string input = "123..";
FontFamily fontFamily = new FontFamily("Arial");
Font testFont = new Font( fontFamily, 16, FontStyle.Regular, GraphicsUnit.Pixel);
Size s = TextRenderer.MeasureText(input, testFont);
Console.WriteLine("Size: height " + s.Height + ", width " + s.Width);
Console.ReadLine();
}
however the result is :

what am I missing here ?
Thanks 🙂
edit
after re-editing the html code by adding a CSS RESET – the code is rendered exactly in all 4 browsers.
so the question remains – why the c# doesnt show me the same result
It seems as if you are trying to compare the size of a string rendered with default Windows font rendering (and any anti-aliasing, ClearType settings etc that are default on your system) and compare that to the rendering done by browsers on Windows which may or may not have their own font rendering engines. As far as I know, Gecko (Firefox) and Webkit (Chrome, Safari) implement their own font rendering so they can present HTML/CSS consistently across different platforms.
So basically, even if you could get your C# code to agree, the result is fairly meaningless as you are comparing apples and oranges! See “Current Implementations” in this article.