When you edit a TLabel’s caption in the form designer, it resizes the TLabel for you. Is there any way I can get a TMemo to do that, at runtime?
I’d like to be able to take a TMemo, assign something to its .lines.text property, and then tell it to resize itself and not exceed a certain width, though it can get as tall as it wants to. Anyone know how to do that?
Set the
WordWrapproperty of theTMemoto true, dump your text into it, count the lines, and set the height to the product of the line count and the line height, but you need to know the line height.The
TMemodoes not expose a line height property, but if you’re not changing the font or font size at runtime, you can determine the line height experimentally at design time.Here’s the code I used to set the height of the
TMemothat had a line height of 13 pixels. I also found that I needed a small constant to account for theTMemo‘s top and bottom borders. I limited the height to 30 lines (396 pixels) to keep it on the form.If you absolutely must extract the line height from the object at runtime, then you might use Someone’s answer. Or, you can use
TRichEdit, which has theSelAttributesproperty containing aHeightproperty giving the line height.-Al.