I can set fixed height in pixels, but i'd like to set it in lines. Sort of like in html you can set height of an textarea to number of rows/lines.
For a TextBox, set the MinLines and MaxLines properties. To better approximate an HTML textarea, consider also setting TextWrapping, VerticalScrollBarVisibility, and AcceptsReturn as follows:
<TextBox TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" AcceptsReturn="True" MinLines="3" MaxLines="3"/>
You could FormattedText to measure the size of text, 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);
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);
Here you are !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With