cAkk:
RX我以前用过,rxrichedit确实是个好东西。我感觉你这个问题并不困难,也许是我没理解?
你看看下面的代码能不能完成你的要求。
unit rtf;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, RxRichEd, ComCtrls, ExtCtrls,Clipbrd;
type
TForm1 = class(TForm)
RxRichEdit1: TRxRichEdit;
Image1: TImage;
Button3: TButton;
Button4: TButton;
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
SavedPlace,SavedLength:Integer;
implementation
{$R *.DFM}
procedure TForm1.Button4Click(Sender: TObject);
var
i:integer;
s:string;
begin
{本过程是做文本变图形的}
s:='THIS STRING WILL BE REPLACED!'; //要找的串
i:=RxRichEdit1.FindText(s,0,length(RxRichEdit1.Text),[]);
if i<>-1 then begin
SavedPlace:=i;
SavedLength:=length(s); //存储要替换的位置和长度
RxRichEdit1.SelStart:=i;
RxRichEdit1.SelLength:=length(S);
RxRichEdit1.SelAttributes.Hidden:=true;//rxrichedit的新特性,可以隐藏
Clipboard.Assign(Image1.Picture.Bitmap);
RxRichEdit1.SelStart:=i+length(S);
RxRichEdit1.PasteFromClipboard;//在串尾加入图形
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
{本过程是做图形变文本的}
with RxRichEdit1 do begin
SelStart:=SavedPlace;
SelLength:=SavedLength;
SelAttributes.Hidden:=False; //恢复被隐藏的文本
SelStart:=SavedPlace+SavedLength;
SelLength:=1;
if SelectionType=[StObject] then
ClearSelection; //清除图形
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RxRichEdit1.Lines.LoadFromFile('c:/1.rtf');
end;
end.