如何在RichEdit1中将name的字符全部找出来并改变颜色?(0分)

  • 主题发起人 主题发起人 laohe
  • 开始时间 开始时间
L

laohe

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢大侠,现在没钱了
 
呵呵,你可以用RichEdit的FindText方法找到它,然后在用代码把name字符选中一下,设置它的
SelAttributes为你想要的Attributes(这里可以设置字体颜色等等)
 
大侠;主要是如何寻找,
 
没钱就不能帮忙吗
 
呵呵,不会寻找吗?看帮助呗:

This example requires a TRichEdit, a TButton, and a TFindDialog.
Clicking the button click will display a Find Dialog to the right of the edit control. Filling in the "Find what" text and pressing the Find Next button will select the first matching string in the Rich Edit control that follows the previous selection.

procedure TForm1.Button1Click(Sender: TObject);

begin
FindDialog1.Position := Point(RichEdit1.Left + RichEdit1.Width, RichEdit1.Top);
FindDialog1.Execute;
end;

procedure TForm1.FindDialog1Find(Sender: TObject);
var
FoundAt: LongInt;
StartPos, ToEnd: Integer;
begin
with RichEdit1 do
begin
{ begin the search after the current selection if there is one }
{ otherwise, begin at the start of the text }
if SelLength <> 0 then

StartPos := SelStart + SelLength;
else

StartPos := 0;

{ ToEnd is the length from StartPos to the end of the text in the rich edit control }

ToEnd := Length(Text) - StartPos;

FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]);
if FoundAt <> -1 then
begin
SetFocus;
SelStart := FoundAt;
SelLength := Length(FindDialog1.FindText);
end;
end;
end;
 
后退
顶部