I am trying to estimate the width in a pixel if the text will be displayed in Chrome using C # for a specific font (Arial 18px) in the tool that I am creating.
Comparison of my results with this tool (uses a browser to visualize the width): http://searchwilderness.com/tools/pixel-length/ line:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit."
Calculated as a width of 439 pixels.
But with this code in C #, I get 445px:
var font = new Font("Arial", 18, FontStyle.Regular, GraphicsUnit.Pixel); var text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; var size = TextRenderer.MeasureText(text, font, new Size(int.MaxValue, int.MaxValue), TextFormatFlags.NoPadding);
Can I change my code to look like a browser?
I tried to display a label with font and text and compare with the rendering of the browser that they correspond to (+/- 1px).
c #
Niels bosma
source share