How to set the height of a text block / text field to 3 lines?

I can set a fixed height in pixels, but I would like to set it in rows. As in html, you can set the height of the text field to the number of lines / lines.

+5
source share
3 answers

Try 3em

1em is equal to the current font size. 2em means 2 times the size of the current font. For example, if an element is displayed with a font of 12 pt, then "2em" is equal to 24 pt.

-3
source

For TextBox, set the MinLines and MaxLines properties. To better approximate the HTML text box, also consider setting TextWrapping, VerticalScrollBarVisibility, and AcceptsReturn as follows:

<TextBox TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" AcceptsReturn="True" MinLines="3" MaxLines="3"/>
+4

1

Text , :

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);

2

Graphics ( ):

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);

!

+2

All Articles