The Java version of this question has been answered, and, well, I donβt know how to do this in .net.
So how do you calculate the display width of a string in C # /. Net?
You have the same problem on this issue as on the Java question - not enough information! It will be different between WinForms and WPF.
For WinForms: Graphics.MeasureString
For WPF, I'm not sure, but I suspect that it will depend on how you draw the text ...
An alternative for Windows Forms is the static TextRenderer.MeasureText method.
Although limited to integer sizes, this one (in tandem with TextRenderer.DrawText) displays a more accurate and significantly better ClearType text than the Graphics.MeasureString / DrawString duo.
In WPF you should use FormattedText .
Graphics.MeasureString , but it's a little flabby, as explained and improved; here
Graphics.MeasureString
You would use Graphics.MeasureString.
http://msdn.microsoft.com/en-us/library/6xe5hazb.aspx
Graphics.MeasureString ([text to measure], [font used to measure text]);
The resulting object will provide the following:
Other MeasureString overloads are also available.