<< Click to Display Table of Contents >> Navigation: Programming > WPTools Premium > Text boxes > Dynamically create textboxes on certain pages |
In case you need to create textboxes on certain pages dynamically, you can use the event OnGetSpecialText for this.
This event is triggered by the formatting routine to request a header (or footer) text for a certain page.
// Paint current text box
procedure TForm5.WPRichText1GetSpecialText(Sender: TObject; Par: TParagraph;
posinpar, pagenr: Integer; Kind: TWPPagePropertyKind; var IsLastPage,
UseThis: Boolean; var SpecialText: TWPRTFDataBlock);
var
rtfdata : TWPRTFDataBlock;
textobj : TWPTextObj;
aName : string;
begin
if Kind=wpIsHeader then
begin
aName := 'HEADER#' + IntToStr(pagenr);
SpecialText := WPRichText1.HeaderFooter.Get(wpIsHeader,wpraNamed , aName );
if SpecialText.Empty then
begin
rtfdata := nil;
textobj := WPRichText1.TextObjects.InsertTextBox(3000,1000,rtfdata, SpecialText.FirstPar);
textobj.Wrap := wpwrNone;
if rtfdata<>nil then
begin
rtfdata.RtfText.AsString :=
'This box is in header #' + IntToStr(pagenr);
textobj.RelY := 2000;
end;
textobj := WPRichText1.TextObjects.InsertTextBox(3000,1000,rtfdata, SpecialText.FirstPar);
textobj.Wrap := wpwrNone;
if rtfdata<>nil then
begin
rtfdata.RtfText.AsString :=
'This box is also in header #' + IntToStr(pagenr);
textobj.RelY := 2000;
textobj.RelX := 5000;
end;
SpecialText.FirstPar.Append('This is the header on page ' + IntToStr(pagenr));
WPRichText1.DelayedReformat;
end;
UseThis := true;
end;
end;
Please note that you cannot save the created text in RTF format since RTF does not support named textboxes.