RTFLabel autosizing problem

A technique to get this size is implemented in TAdvStringGrid.
Descend from TRichEdit and implement the CNNotify() message handler. Then toggle the RIchEdit.WordWrap property and this should trigger the EN_REQUESTRESIZE notification from where you can retrieve the width/height:


Snippet from TAdvStringGrid code for inplace rich text autosizing:

procedure TAdvRichEdit.CNNotify(var Msg: TWMNotify);
type
  PREQRESIZE = ^TREQRESIZE;
  TREQRESIZE = record
    NMHdr: TNMHdr;
    rc: TRect;
  end;
var
  ReqResize: PREQRESIZE;
  NewHeight: Integer;
  R: TRect;
  VerInfo: TOSVersionInfo;
begin
  if Msg.NMHdr^.Code = EN_REQUESTRESIZE then
  begin
    ReqResize := PREQRESIZE(Msg.NMHdr);

    if not (csDesigning in ComponentState) then
    begin
      if FGrid.RichEdit.HandleAllocated then
      begin
        if Msg.NMHdr^.hwndFrom = FGrid.RichEdit.Handle then
        begin
          FGrid.RichEdit.FReqWidth := ReqResize^.rc.Right - ReqResize^.rc.Left;
          FGrid.RichEdit.FReqHeight := ReqResize^.rc.Bottom - ReqResize^.rc.Top;
        end;
      end;