新しい行ではなく、既存の最後の行にテキストを追加するにはどうすればよいですか? Lines.Add と Lines.Append は新しい行としてテキストを追加し、Lines.Insert は見つけ方がわからない位置を必要とします。
7359 次
3 に答える
3
最後の行自体、またはコンテンツ全体を使用できます。
// RE = TRichEdit, Temp = string;
// Last line only
Temp := RE.Lines[RE.Lines.Count - 1];
Temp := Temp + ' plus some new text';
RE.Lines[RE.Lines.Count - 1] := Temp;
// The entire content
Temp := RE.Text;
Temp := Temp + ' plus some new text';
RE.Text := Temp;
特に RichEdit に大量のテキストが含まれている場合は、最初の方法の方が優れていることに注意してください。RichEdit.Text の読み取りと書き込みでは、メモリ内で大量のテキストを移動する必要があります。
編集:私の答えに対するOPのコメントの後:
テキストをフォーマットするには、追加する前に SelStart を保存してから、SelLength と SelAttributes を使用してフォーマットを適用します。
// StarPos and Len are both Integers.
StartPos := Length(RE.Text);
Len := Length(YourNewTextToBeAdded);
// Do stuff here to add text
RE.SelStart := StartPos;
RE.SelLength := Len;
RE.SelAttributes.Style := RE.SelAttributes.Style + [fsBold];
于 2009-12-31T18:42:03.603 に答える
1
実行
with RichEdit1 do
begin
Lines.Add(s);
Perform( EM_SCROLL, SB_LINEDOWN, 0);
end;
于 2015-07-15T09:06:30.387 に答える
1
「Strings」および「Count」プロパティを使用できます。
RichEdit1.Lines.Strings[RichEdit1.Lines.Count-1]:=RichEdit1.Lines.Strings[RichEdit1.Lines.Count-1]+'Text';
于 2009-12-31T18:37:25.313 に答える