Posted by webmaster Guido on March 20, 2008
In Reply to Re: About Rich Edit Box posted by RussCAp12602 on
March 19, 2008
: Thanks for the reply! One question: What do the numbers 100 and 200 in the code refer
to? I'm guessing "pixels".
: I'm limited as to what I can do because of what is allowed by Turbo Delphi
6. For example, I can't add any controls.
In the previous code, the numbers 100 and 200 are the positions in points of the tab stops.
As promised, here's also a source code example for printing a RichEdit; I tested it with the free Turbo Delphi Explorer :))
The following procedure accepts parameters for the left, right, top and bottom margins in inches, the number of copies to be printed and the title of the printjob:
procedure TForm1.PrintRichEdit(LMargin, RMargin, TMargin, BMargin: real; Copies: integer; JobTitle: string); var PixX, PixY, LeftNonPrint, TopNonPrint: integer; R: TRect; begin // Get pixels per inch PixX := GetDeviceCaps(Printer.Handle, LOGPIXELSX); PixY := GetDeviceCaps(Printer.Handle, LOGPIXELSY); // Non-printable margins LeftNonPrint := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX); TopNonPrint := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY); // Set the margins R.Left := Round(LMargin * PixX) - LeftNonPrint; R.Right := Printer.PageWidth - LeftNonPrint - Round(RMargin * PixX); R.Top := Round(TMargin * PixY) - TopNonPrint; R.Bottom := Printer.PageHeight - Round(BMargin * PixY) - TopNonPrint; RichEdit1.PageRect := R; // Print the desired number of copies while Copies > 0 do begin Application.ProcessMessages; RichEdit1.Print(JobTitle); Dec(Copies); end; end;
How to call this procedure:
procedure TForm1.Button1Click(Sender: TObject); begin PrintRichEdit(1, 1, 1, 1, 1, 'Printing the RichEdit'); end;
Related articles
Follow Ups