I am now facing a problem with getting a string that fits the provided width in pixels.
For example, if I have a sentence like this (in JavaScript):
var mystring = "This is my sentence, I need to get just 50 pixels from it."
If I use the MeasureString
method in C# I can get the width:
Font font = new Font("Segoe UI", 11, FontStyle.Regular, GraphicsUnit.Point);
SizeF size = graphics.MeasureString(mystring, font);
Let's say the width of this string is 400px but the max width I can display on the site is 50px.
If I shorten the string and measure it until it's less than 50px width it works, but it will require many iterations which is not a good solution at all.
Does anyone have a good solution for this?
Thanks.