Delphi 之 TRichEdit组件
TRichEdit组件属性
Lines
用来编辑单行添加文本或删除文本
HideSelection
为true是,组件有焦点,false则无焦点
TRichEdit组件方法
Clear
删除文本
FindText
查找指定的文本
示例
查找RichEdit组件指定的字符串
ibegin:= richedit1.FindText(Edit1.Text,ibegin,Length(RichEdit1.text),[stMatchCase]); if ibegin <> -1 then begin RichEdit1.SetFocus; RichEdit1.SelStart:=ibegin; RichEdit1.SelLength:=1; inc(ibegin); end else if ibegin = -1 then begin ibegin:= 0; Application.MessageBox('没找到变量','提示',MB_OKCANCEL+mb_iconinformation); end;
LoadFromFile
按指定的文件路径将文本内容载入到TRichEdit组件中
示例:将文本文本的内容载入到TRichEdit组件中
procedure TForm1.Button1Click(Sender: TObject); begin if OPenDialog1.Execute then begin RichEdit1.Lines.LoadFromFile(OpenDialog1.FileName); end; end;
带滚动控件
procedure TForm1.BitBtn1Click(Sender: TObject); begin with RichEdit1 do begin SelStart:= Length(text); Perform(EM_SCROLL,0,0); end; end; procedure TForm1.BitBtn2Click(Sender: TObject); begin with RichEdit1 do begin Perform(EM_SCROLL,SB_LINEDOWN,0); end; end; procedure TForm1.Button1Click(Sender: TObject); begin if OpenDialog1.Execute then begin RichEdit1.Lines.LoadFromFile(OpenDialog1.FileName); end; end; end.