2009-12-31 143 views

回答

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]; 
+0

我试过了,它工作。非常感谢。但现在我怎样才能格式化这个添加的文本。 – 2009-12-31 19:28:07

1

您可以使用“字符串”和“计数”属性。编辑1.Lines.Strings [RichEdit1.Lines.Count-1]:= RichEdit1.Lines.Strings [RichEdit1.Lines.Count-1] +'Text';

+0

Lines.Strings []和Lines []是相同的东西; Lines是读写Lines.Strings的默认属性。 – 2009-12-31 18:42:44

1

执行

with RichEdit1 do 
begin 
Lines.Add(s); 
Perform(EM_SCROLL, SB_LINEDOWN, 0); 
end; 
相关问题