You can get the text size using the following solutions:
Solution 1
You can format a Text to measure text size, here is an example:
String text = "Here is my text"; Typeface myTypeface = new Typeface("Helvetica"); FormattedText ft = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, myTypeface, 16, Brushes.Red); Size textSize = new Size(ft.Width, ft.Height);
Decision 2
Use the Graphics class (found here ):
System.Drawing.Font font = new System.Drawing.Font("Calibri", 12, FontStyle.Bold); Bitmap bitmap = new Bitmap(1, 1); Graphics g = Graphics.FromImage(bitmap); SizeF measureString = g.MeasureString(text, font);
There you are!
source share