delphi richedit 指定文字颜色问题
列如:Richedit里面的内容是:sdfashdfljaskldfasdfasdfasdfasdfasdflkasjdklfjasdfasdfasdfasdfasdfa...
列如:
Richedit里面的内容是:
sdfashdfljaskldfa
sdf
asdf
asdfasdfasdflkasjdklfjasdf
asdfasdfasdfasdfasdfasdfasdfdfadsdfasd fasdf delphi
asdfasdfasdfasdfasdfasdf
我怎么让内容里的delphi 颜色变换成红色呢? 展开
Richedit里面的内容是:
sdfashdfljaskldfa
sdf
asdf
asdfasdfasdflkasjdklfjasdf
asdfasdfasdfasdfasdfasdfasdfdfadsdfasd fasdf delphi
asdfasdfasdfasdfasdfasdf
我怎么让内容里的delphi 颜色变换成红色呢? 展开
1个回答
展开全部
var
iPos,iEnd :Integer;
const
Str = 'delphi';
begin
iPos := 0;
repeat
iEnd := Length(RichEdit1.Text) - iPos;
iPos := RichEdit1.FindText(Str,iPos,iEnd,[stWholeWord,stMatchCase]);
if iPos <> -1 then
begin
RichEdit1.SelStart := iPos;
RichEdit1.SelLength := Length(Str);
richedit1.SelAttributes.Color := clRed;
iPos := iPos + Length(Str);
end;
until iPos = -1;
end;
iPos,iEnd :Integer;
const
Str = 'delphi';
begin
iPos := 0;
repeat
iEnd := Length(RichEdit1.Text) - iPos;
iPos := RichEdit1.FindText(Str,iPos,iEnd,[stWholeWord,stMatchCase]);
if iPos <> -1 then
begin
RichEdit1.SelStart := iPos;
RichEdit1.SelLength := Length(Str);
richedit1.SelAttributes.Color := clRed;
iPos := iPos + Length(Str);
end;
until iPos = -1;
end;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询