RTFLabel autosizing problem

Hi,

using RTFLabel is really comfortable except for one thing:

My RTFLabel has a fixed width, whenever I fill my Label with a few lines (using wordwrap) it add automatic linebreaks, which is just fine.
Since the height of the label is different depending on what is filled in, I would like to autosize it.
Can anyone give me a helping hand on this one?

I already tried:

EM_REQUESTRESIZE

without success, but probably I was just not using it in a proper way.
So if anyone could give me a helping hand on this, I would be very grtateful.

Thanks in Advance
Lars

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;