![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
richedit.selattr [D7, XP]
webpauk © (2009-08-03 11:47:00)Чувствую себя дебилом:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
RichEdit1: TRichEdit;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const
cArrColor: array[Boolean] of TColor = (clRed, clBlue);
cArrText: array[Boolean] of String = ('Hello', 'Bye');
var
fWidth: Integer;
fSelStart: Integer;
fText: String;
begin
fSelStart:=RichEdit1.SelStart;
fText:=cArrText[Boolean(TButton(Sender).Tag)];
fWidth:=Length(fText);
RichEdit1.Text:=copy(RichEdit1.Text, 1, fSelStart)+fText+copy(RichEdit1.Text, fSelStart+1, Length(RichEdit1.Text)-fSelStart);
RichEdit1.SelStart:=fSelStart;
RichEdit1.SelLength:=fWidth;
RichEdit1.SelAttributes.Color:=cArrColor[Boolean(TButton(Sender).Tag)];
RichEdit1.SelStart:=fSelStart+fWidth;
RichEdit1.SetFocus;
TButton(Sender).Tag:=Integer(not Boolean(TButton(Sender).Tag));
end;
end.
почему один раз меняется оформление всего текста, а один раз - только части?
Leonid Troyanovsky (2009-08-03 13:14:00) [1]
> webpauk © (03.08.09 11:47)
> RichEdit1.Text:=copy(RichEdit1.Text, 1, fSelStart)+fText+copy(RichEdit1.
> Text, fSelStart+1, Length(RichEdit1.Text)-fSelStart);
RichEdit1.SelText:= fText;
--
Regards, LVT.