how to Justify text in RichEdit ?
i have declared a public procedure for the component TppCustomRichText that
justifies the text in the FRichEdit field. it works fine in design mode, but
when i want to print, the alignment defaults to LeftJustify.
If I want to see the text justified in design mode, i set a flag in the
richeditor (by pressing some button) and if the flag is set i call the
procedure after the richtext editor closes and it displays the text as
justified. but it doesn't work in print preview mode nor when i print the
report. Does anyone know how to solve this problem? Maybe some other way?
And here is the procedure:
procedure TppCustomRichText.Justify;
var x :tparaformat;
L :LongInt;
cp :charrange;
rtemp : TRichEdit;
begin
rTemp := TRichEdit(FRichEdit);
rTemp.Font.Color:=clRed;
with FRichEdit do
begin
x.cbSize := sizeof(x);
if SelLength = 0 then
begin
cp.cpMin := 0;
cp.cpMax := length(Text);
SendMessage(Handle,EM_EXSETSEL,mZERO,LPARAM(@cp));
end;
L := SendMessageA(Handle,EM_SETTYPOGRAPHYOPTIONS,
TO_ADVANCEDTYPOGRAPHY, TO_ADVANCEDTYPOGRAPHY);
if L = 1 then
begin
SendMessageA(Handle, EM_GETTYPOGRAPHYOPTIONS, mZERO, mZERO);
SendMessage(Handle, EM_GETPARAFORMAT, mZERO, LPARAM(@x));
x.dwMask := PFM_ALIGNMENT;
x.wAlignment := PFA_JUSTIFY;
SendMessage(Handle, EM_SETPARAFORMAT, mZERO, lparam(@x));
end;
cp.cpMin := 0;
cp.cpMax := 0;
SendMessage(Handle,EM_EXSETSEL,mZERO,lparam(@cp));
// TppPrintAble(FRichEdit).TextAlignment := taFullJustified;
WordWrap := true;
end;
Reset;
PropertyChange;
end;
Denilso F. Brustelo
SMARapd Inform?tica Ltda
justifies the text in the FRichEdit field. it works fine in design mode, but
when i want to print, the alignment defaults to LeftJustify.
If I want to see the text justified in design mode, i set a flag in the
richeditor (by pressing some button) and if the flag is set i call the
procedure after the richtext editor closes and it displays the text as
justified. but it doesn't work in print preview mode nor when i print the
report. Does anyone know how to solve this problem? Maybe some other way?
And here is the procedure:
procedure TppCustomRichText.Justify;
var x :tparaformat;
L :LongInt;
cp :charrange;
rtemp : TRichEdit;
begin
rTemp := TRichEdit(FRichEdit);
rTemp.Font.Color:=clRed;
with FRichEdit do
begin
x.cbSize := sizeof(x);
if SelLength = 0 then
begin
cp.cpMin := 0;
cp.cpMax := length(Text);
SendMessage(Handle,EM_EXSETSEL,mZERO,LPARAM(@cp));
end;
L := SendMessageA(Handle,EM_SETTYPOGRAPHYOPTIONS,
TO_ADVANCEDTYPOGRAPHY, TO_ADVANCEDTYPOGRAPHY);
if L = 1 then
begin
SendMessageA(Handle, EM_GETTYPOGRAPHYOPTIONS, mZERO, mZERO);
SendMessage(Handle, EM_GETPARAFORMAT, mZERO, LPARAM(@x));
x.dwMask := PFM_ALIGNMENT;
x.wAlignment := PFA_JUSTIFY;
SendMessage(Handle, EM_SETPARAFORMAT, mZERO, lparam(@x));
end;
cp.cpMin := 0;
cp.cpMax := 0;
SendMessage(Handle,EM_EXSETSEL,mZERO,lparam(@cp));
// TppPrintAble(FRichEdit).TextAlignment := taFullJustified;
WordWrap := true;
end;
Reset;
PropertyChange;
end;
Denilso F. Brustelo
SMARapd Inform?tica Ltda
This discussion has been closed.
Comments
memo or one that changes for every record. If so then you probably have to
call this every time the text is set, ie the OnPrint event. Otherwise you
can do it in the report's BeforePrint event.
--
Cheers,
Alexander Kramnik
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com