Ok, here’s the problem. I have a label component in a panel. The label is aligned as alClient and has wordwrap enabled. The text can vary from one line to several lines. I would like to re-size the height of the the panel (and the label) to fit all the text.
How do I get the necessary height of a label when I know the text and the width of the panel?
You can use the TCanvas.TextRect method, along with the tfCalcRect and tfWordBreak flags :
TCanvas.TextRectwraps a call to theDrawTextExfunction from the Windows API.The
tfCalcRectandtfWordBreakflags are delphi wrappers for the valuesDT_CALCRECTandDT_WORDBREAKof the windows API. You can find detailed information about their effects in theDrawTextExdocumentation on msdn