Re:TRichEdit Question (Printing question)
In article <39D0C6F3.F4887...@mailbr.com.br>, Cristiano Roberto Hansen
wrote:
Quote
> I have a question: how can I configure a TRichEdit with A4 paper size
> for printing?
Cristiano,
use the PageRect property of the richedit. It allows you to define a
printing area relative to the printable area of the paper currently
selected for the active printer.
Printing from a rich edit with margins:
the TRichedit has a property PageRect that you can use to define the
region on the page where printing should take place. The online help
states that the units to use are twips but that is *wrong*! Use printer
device units (dots, the default), the control converts them to twips
internally.
procedure TForm1.Button1Click(Sender: TObject);
var
presX, presY: Integer;
r: TRect;
Begin
with richedit1 do begin
plaintext := true;
lines.loadfromfile( changefileext( application.exename, '.DPR' ));
end;
presX := GetDeviceCaps( printer.handle, LOGPIXELSX );
presY := GetDeviceCaps( printer.handle, LOGPIXELSY );
with r do begin
left := presX; // 1 inch left margin
top := 3 * presY div 2; // 1.5 inch top margin
right := Printer.PageWidth - 3 * presX div 4; // 0.75 inch right
margin
bottom := Printer.PageHeight - presY; // 1 inch bottom margin
end;
with richedit1 do begin
Pagerect := r;
Print('Testjob');
end;
End;
end.
Note that the margins in the example are relative to the printable area
of the page, not the physical page. To correct for the nonprintable
margin use GetDeviceCaps with PHYSICALOFFSETX and PHYSICALOFFSETY (this
tells you how far the page coordinate system has been shifted left and
down by Delphi to put the origin at the upper left corner of the
printable area) and PHYSICALWIDTH and PHYSICALHEIGHT to get the paper
size in device units.
Peter Below (TeamB) 100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!