fillpageunit1.pas
来自「wptools5 pro 完整源代码 Msword界面的文本编辑器源代码」· PAS 代码 · 共 126 行
PAS
126 行
unit FillPageUnit1;
{ This demo shows how to create text using information about the current location
on the page. We also show how to optimize this process, by formatting only the
current page most of the time - ReformatAll is only used when a page break is
likely to be required }
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, WPRTEDefs, WPCTRMemo, WPCTRRich, StdCtrls, ExtCtrls;
type
TWPAddTextTest = class(TForm)
Panel1: TPanel;
ClearBtn: TButton;
AddBtn: TButton;
WPRichText1: TWPRichText;
AddOpt: TButton;
Optimized: TCheckBox;
Label1: TLabel;
procedure ClearBtnClick(Sender: TObject);
procedure AddBtnClick(Sender: TObject);
procedure AddOptClick(Sender: TObject);
private
{ Private-Deklarationen }
public
testtext : string;
tab1, tab2 : Integer; // twip pos
end;
var
WPAddTextTest: TWPAddTextTest;
implementation
{$R *.dfm}
procedure TWPAddTextTest.ClearBtnClick(Sender: TObject);
begin
WPRichText1.Clear;
WPRichText1.Header.SetPageWH(
WPCentimeterToTwips(21),
WPCentimeterToTwips(29.7),
WPCentimeterToTwips(1),
WPCentimeterToTwips(1),
WPCentimeterToTwips(1),
WPCentimeterToTwips(1) );
WPRichText1.CheckHasBody;
testtext := '%d This is some text at Y position'
+#9
+'%f' +
#9 +
'inch';
tab1 := WPInchToTwips(4);
tab2 := WPInchToTwips(4.1);
end;
procedure TWPAddTextTest.AddBtnClick(Sender: TObject);
var i : Integer;
begin
for i:=1 to 10 do
begin
WPRichText1.InputString(
Format(testtext, [i,WPRichText1.GetYPositionTw/1440]));
WPRichText1.ActiveParagraph.TabstopAdd(
tab1, tkRight, tkDots);
WPRichText1.ActiveParagraph.TabstopAdd(
tab2, tkLeft);
WPRichText1.InputString(#13);
// Without the "ReformatAll" we do not know where we are!
WPRichText1.ReformatAll(false, false);
end;
WPRichText1.Invalidate;
end;
procedure TWPAddTextTest.AddOptClick(Sender: TObject);
var i, maxy, ypos, frompage : Integer;
tim : Cardinal;
begin
WPRichText1.Clear;
WPRichText1.CheckHasBody;
tim := GetTickCount;
// from here wee need ReformatAll
maxy := WPRichText1.Header.PageHeight-
WPRichText1.Header.BottomMargin -
WPRichText1.Header.TopMargin - 720;
for i:=1 to 2000 do
begin
Label1.Caption := IntToStr(i);
ypos := WPRichText1.GetYPositionTw;
if not Optimized.Checked or (ypos>maxy) then
frompage := -1
else frompage := WPRichText1.CPPage;
WPRichText1.InputString(
Format(testtext, [i,ypos/1440]));
WPRichText1.ActiveParagraph.TabstopAdd(
tab1, tkRight, tkDots);
WPRichText1.ActiveParagraph.TabstopAdd(
tab2, tkLeft);
WPRichText1.InputString(#13);
// Without the "ReformatAll" we do not know where we are!
if frompage<0 then
WPRichText1.ReformatAll(false, false)
else WPRichText1.BodyText.Reformat(frompage,frompage+1);
Label1.Update;
end;
WPRichText1.InputString('Pagecount: ' + IntToStr(WPRichText1.CountPages));
WPRichText1.Invalidate;
Label1.Caption := 'done in mms' + IntToStr(GetTickCount-tim);
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?