Ive made a small program, where you enter a bunch of stuff and it puts it into a rich edit, but now how would I print the contents of the rich edit?

I was thinking about RichEdit1.print();, but i dont know what to put in the brackets. The rich edit has 6 different margins (2 for each different item (Name, quantity and Price))

If someones willing to help, it would be much appreciated!

有帮助吗?

解决方案

Pass a single parameter, a string containing the name of the print job. This name will appear in the print manager, if the documentation is to be believed:

Use Print to print the contents of a rich edit control. The Caption parameter specifies the title that appears in the print manager and on network title pages.

You also need to set PageRect before printing. This defines the page dimensions on the printer. You need to query the device capabilities for the chosen printer, and apply any margins. I do that with this helper function:

procedure PrintRichEdit(RichEdit: TRichEdit; const Caption: string; 
  const PrinterMargin: Integer);
//the units of TRichEdit.PageRect are pixels, units of PrinterMargin are mm
var
  PrinterHeight, PrinterWidth: Integer;
  LogPixels, PrinterTopLeft: TPoint;
  PageRect: TRect;
  Handle: HDC;
begin
  Handle := Printer.Handle;
  LogPixels := Point(GetDeviceCaps(Handle, LOGPIXELSX),
    GetDeviceCaps(Handle, LOGPIXELSY));
  PrinterTopLeft := Point(GetDeviceCaps(Handle, PHYSICALOFFSETX), 
    GetDeviceCaps(Handle, PHYSICALOFFSETY));
  PrinterWidth := Printer.PageWidth;
  PrinterHeight := Printer.PageHeight;
  PageRect.Left := Max(0, Round(PrinterMargin*LogPixels.X/25.4)
    - PrinterTopLeft.X);
  PageRect.Top := Max(0, Round(PrinterMargin*LogPixels.Y/25.4)
    - PrinterTopLeft.Y);
  PageRect.Right := PrinterWidth-PageRect.Left;
  PageRect.Bottom := PrinterHeight-PageRect.Top;
  if (PageRect.Left>=PageRect.Right) or (PageRect.Top>=PageRect.Bottom) then
    //the margins are too big
    PageRect := Rect(0, 0, 0, 0);
  RichEdit.PageRect := PageRect;
  RichEdit.Print(Caption);
end;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top