打印整个form 以及form里面所有内容

解决方案 »

  1.   

    For Example:
    procedure TFormPrintWindows.ButtonPrintPanelClick(Sender: TObject);
    var
      Bitmap: TBitmap;
      FromLeft, FromTop, PrintedWidth, PrintedHeight: Integer;
    begin
      Printer.BeginDoc;
      try
        Bitmap := TBitmap.Create;
        try
          Bitmap.Width := Panel1.Width;
          Bitmap.Height := Panel1.Height;
          Bitmap.PixelFormat := pf24bit;  {Avoid palettes}
          {Copy the panel area from the form into a separate bitmap}
          Bitmap.Canvas.CopyRect(Rect(0, 0, Bitmap.Width, Bitmap.Height), FormPrintWindows.Canvas,
                                                          Rect(Panel1.Left, Panel1.Top, Panel1.Left + Panel1.Width - 1,
                                                          Panel1.Top + Panel1.Height - 1) );
          {Assumes 10% left, right and top margin}
          {Assumes bitmap aspect ratio > ~0.75 for portrait mode}
          PrintedWidth := MulDiv(Printer.PageWidth, 80, 100);  {80%}
          PrintedHeight := MulDiv(PrintedWidth, Bitmap.Height, Bitmap.Width);
          FromLeft := MulDiv(Printer.PageWidth, 10, 100);  {10%}
          FromTop := MulDiv(Printer.PageHeight, 10, 100);  {10%}
          PrintBitmap(Printer.Canvas, Rect(FromLeft, FromTop, FromLeft + PrintedWidth,
                                  FromTop + PrintedHeight), Bitmap);
        finally
          Bitmap.Free
        end;
      finally
        Printer.EndDoc
      end;
    end;