Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#3

Re: Höhe von TMemo an Textlänge anpassen

  Alt 10. Sep 2008, 11:02
Hallo,

Probier mal das:

Delphi-Quellcode:
procedure TForm1.AdjustMemoHeight(Memo: TMemo);
var
  Rect1, Rect2: TRect;
  S: string;
Begin
  with Memo do
  begin
    s := Text;
    Perform(EM_GETRECT, 0, Longint(@Rect1));
    Rect2 := Rect1;
    Self.Canvas.font := Font;
    DrawTextEx(Canvas.Handle, PChar(S), Length(S), Rect2,
              DT_CALCRECT or DT_EDITCONTROL or DT_WORDBREAK or DT_NOPREFIX, nil);
    Height := Height + Rect2.Bottom - Rect1.Bottom;
  end;
end;
Thomas
  Mit Zitat antworten Zitat