Note that there are some explanatory texts on larger screens.

plurals
  1. POMeasure string as if it would be on html?
    primarykey
    data
    text
    <p>I have the exact string : <kbd>123..</kbd></p> <p>I want to see what its length would be as <em>if it was on a Html page</em> ( as SPAN)</p> <pre><code>font-name:arial font-size:16px; </code></pre> <p>I made an experiment : </p> <p><a href="http://jsbin.com/axezib/edit#preview" rel="nofollow noreferrer">http://jsbin.com/axezib/edit#preview</a></p> <p>so </p> <pre><code>&lt;span style="font-family:arial;border:solid 1px red;display:inline-block;font-size:16px;"&gt;123..&lt;/span&gt; </code></pre> <p>is rendered to : </p> <p><img src="https://i.stack.imgur.com/e46Me.jpg" alt="enter image description here"></p> <p>and its properties : </p> <p><kbd>ofcourse * { padding:0px;margin:0px; }</kbd></p> <p><img src="https://i.stack.imgur.com/wBjus.jpg" alt="enter image description here"></p> <p>as you can see its width is 35 and height=19. ( <em>lets ignore the border</em> ...)</p> <p>however I have this code which should (<em>or not</em>) tell me the same result : </p> <pre><code>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(); } </code></pre> <p>however the result is : </p> <p><img src="https://i.stack.imgur.com/ndqNF.jpg" alt="enter image description here"></p> <p>what am I missing here ?</p> <p>Thanks <kbd>:-)</kbd></p> <h1>edit</h1> <p>after <a href="http://jsbin.com/axezib/2/edit#javascript,html" rel="nofollow noreferrer">re-editing</a> 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</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload