Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:30:25+00:00 2026-06-07T00:30:25+00:00

I have the exact string : 123.. I want to see what its length

  • 0

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 :

enter image description here

and its properties :

ofcourse *
{
padding:0px;margin:0px;
}

enter image description here

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 :

enter image description here

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:30:26+00:00Added an answer on June 7, 2026 at 12:30 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to display this exact string in HTML: ;amp& When I try it
How to match exact string/word while searching a list. I have tried, but its
How to match exact string/word while searching a list. I have tried, but its
I have an array with french strings let say: égrener and exact I would
I have this exact issue ASP.net can’t update page from event handler and it's
I have the exact same html sitting on two different servers. Both pages call
I swear, I have this exact thing working on another page. I'm such a
I have a String array which I want to convert to specifc format. For
I'm having a problem using the exact string length, %Ns, format modifier in sscanf.
Say I have a string with various words of unknown length. I plan to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.