📄 changeattru.pas
字号:
unit ChangeAttrU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, WPRTEDefs, WPCTRMemo, WPCTRRich;
type
TForm1 = class(TForm)
WPRichText1: TWPRichText;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Button3: TButton;
Memo1: TMemo;
Panel2: TPanel;
Button4: TButton;
CenterHeader: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure WPRichText1DelayedUpdate(Sender: TObject;
var WPUPD_Code: Integer; Param: Integer);
procedure Button4Click(Sender: TObject);
procedure CenterHeaderClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var par : TParagraph;
begin
WPRichText1.Clear;
// Input String uses the current writing mode
WPRichText1.InputString('Created with WPRichText1.InputString(...);');
//***************************************************************************
// Now we create a paragraph the direct way:
par := TParagraph.Create(WPRichText1.ActiveText);
WPRichText1.ActiveText.AppendPar(par);
// Set the text
par.SetText('Created with:' + #10
+ 'par := TParagraph.Create(WPRichText1.ActiveText);' + #10
+'WPRichText1.ActiveText.AppendPar(par)' + #10
+'par.SetText(..)' + #10
+'par.ASetFontName(''Courier New'');' + #10
+'par.ASetColor(WPAT_CharColor, clGreen);' + #10
+'par.ASet(WPAT_IndentLeft,360);' + #10
+'par.ASet(WPAT_IndentFirst,-360);');
// and some propereties
par.ASetFontName('Courier New');
par.ASetColor(WPAT_CharColor, clGreen);
par.ASet(WPAT_IndentLeft,360);
par.ASet(WPAT_IndentFirst,-360);
//***************************************************************************
// Now we need some mixed attributes in the same text. We are using
// WPRichText1.TextCursor with InputString. Of course we could also
// use WPRichText1.CurrAttr
WPRichText1.CPPosition := MaxInt;
WPRichText1.InputString(#13);
WPRichText1.ActiveParagraph.ClearProps;
WPRichText1.InputString('Default ');
WPRichText1.TextCursor.WritingTextAttr.SetFontName('Courier New');
WPRichText1.InputString('Courier New ');
WPRichText1.TextCursor.WritingTextAttr.SetFontName('Times New Roman');
WPRichText1.InputString('Times New Roman');
end;
procedure TForm1.Button2Click(Sender: TObject);
var col : Integer;
begin
col := WPRichText1.CurrAttr.ColorToNr(clRed, true);
WPRichText1.CPPosition := 0;
repeat
if WPRichText1.CPChar in ['A'..'Z'] then
begin
WPRichText1.CPAttr.BeginUpdate;
WPRichText1.CPAttr.Color := col;
WPRichText1.CPAttr.IncludeStyle(afsBold);
WPRichText1.CPAttr.EndUpdate;
end;
until not WPRichText1.CPMoveNext;
WPRichText1.Refresh;
end;
procedure TForm1.Button3Click(Sender: TObject);
var par : TParagraph;
i : Integer;
a : TWPCharAttr;
props : TWPRTFProps;
begin
par := WPRichText1.FirstPar;
props := WPRichText1.ActiveText.RTFProps;
while par<>nil do
begin
for i:=0 to par.CharCount-1 do
begin
if (par.CharItem[i]>='A') and (par.CharItem[i]<='Z') then
begin
props.Attributes.GetCharAttr(par.CharAttr[i],a);
props.AttrInterface.SetColor(a, clRed);
props.AttrInterface.IncludeStyle(a, afsBold);
props.Attributes.SetCharAttr(par.CharAttr[i],a);
end;
end;
par := par.next;
end;
WPRichText1.Refresh;
end;
procedure TForm1.WPRichText1DelayedUpdate(Sender: TObject;
var WPUPD_Code: Integer; Param: Integer);
var s : string;
i : Integer;
par : TParagraph;
begin
if WPUPD_Code=WPUPD_ShowCursor then
begin
par := WPRichText1.ActiveParagraph;
s := '';
if par<>nil then
for i:=0 to par.CharCount-1 do
s := s+ IntToStr(par.CharAttr[i] and $FFFF) + #32;
Memo1.Text := s + #13 + #10 +
par.StyleString + #13 + #10 + 'CharAttr:' +
WPRichText1.CPAttr.Ex.AGetWPSS;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var par : TParagraph;
link_tag : TWPTextObj;
begin
par := WPRichText1.ActiveText.AppendNewPar(false);
par.Append('This is a link: ');
link_tag := par.AppendNewObjectPair(wpobjHyperlink,'WPCubed GmbH');
link_tag.Source := 'http://www.wpcubed.com';
// and dome more text
par.Append(' (click)');
WPRichText1.Refresh();
end;
procedure TForm1.CenterHeaderClick(Sender: TObject);
var par : TParagraph;
begin
par := WPRichText1.HeaderFooter.Get(wpHeader, wpraOnAllPages).FirstPar;
while par<>nil do
begin
par.ASet(WPAT_Alignment, Integer(paralCenter));
par := par.next;
end;
WPRichText1.Refresh;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -