簡體   English   中英

如何設置TMemo高度以填充Delphi firemonkey中的文本內容

[英]How to set the TMemo height to fill text content in Delphi firemonkey

我正在使用XE7。

我在運行時創建了TMemo。

我需要擴大您的高度以顯示所有文本行。

我已經嘗試過在stackoverflow上找到的這些功能,但是它們無法正常工作。

Memo.height:=get_memo_height(aMemo)Memo.height:=ResizeMemo(aMemo)

我得到的身高小於實際身高。

問候,路易斯

//doesnt work
function get_memo_height(amemo:tmemo):single;
    var i:integer;
        astring:string;
        layout:ttextlayout;

    begin
      Layout := TTextLayoutManager.DefaultTextLayout.Create;
      astring:='';
      for i:=0 to amemo.lines.count-1 do astring:=astring+amemo.lines[i]+chr(10);
      Layout.BeginUpdate;
      Layout.Text :=astring;
      Layout.WordWrap := amemo.wordwrap;
      Layout.HorizontalAlign := amemo.TextAlign;
      Layout.MaxSize := PointF(amemo.width-amemo.ContentBounds.width,maxint);
      Layout.VerticalAlign := tTextAlign.taLeading;
      Layout.Font := amemo.Font;
      Layout.TopLeft := pointf(0,0);
      Layout.EndUpdate;
      result:=layout.textrect.bottom;
      Layout.free;
    end;



    //doesnt work
    function ResizeMemo(AMemo: TMemo):single;
    const
      Offset = 4; //The diference between ContentBounds and ContentLayout
    begin
      result := AMemo.ContentBounds.Height + Offset;
    end;

嘗試以下工作:

將TText組件放在TMemo中,並與mostTop對齊,將Autosize True,HistTest False和Opacity設置為0

然后執行以下操作:

procedure TfnuevoItem.Memo1KeyUp(Sender: TObject; var Key: Word;
  var KeyChar: Char; Shift: TShiftState);
begin
  Text1.Height:=0;
  Text1.Text:=Memo1.Text;
  Text1.RecalcSize;
  Memo1.Height:=Text1.Height+10; // set 10 or more offset
end;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM