I have a long string (~100k characters). I need to know the length for this string. I call
Size s = TextRenderer.MeasureText(graphics, text, font);
But it returns width equals 7. Only if text length <= 43679 it returns correct value!
Also, if I insert the text in the text box, the text is not visible in the text box! I can select text with mouse, copy via "Ctrl+C", but text not visible. MaxLength property is more than the text length.
I've looked on msdn, but haven't found any information about maximum text length which is used in MeasureText and TextBox.
Where I can find documentation about this? Is there any way to increase maximum text length? Do these values depend on the operating system and computer performance?
Try using this code for measuring strings, textrenderer isnt accurate
credit to problem with TextRenderer.MeasureText
Other then that also try using stringbuilder with long strings and then even split the strings into smaller ones and measure those and add it together
Similar example was given Here . Also they addressed the maxLength issue on msdn
Important : See how the MaxLength is used in the article.
Source