TRMVirtualPreview.DlgPageSetup procedure TRMVirtualPreview.DlgPageSetup; var tmpForm: TRMPageSetupForm; liEndPage: TRMEndPage; lPage: TRMCustomPage; i: Integer; lPageWidth, lhRgn, lPageSize: Integer; lOldIndex: Integer; begin if FPrepareReportFlag or (GetEndPages = nil) then Exit; liEndPage := TRMEndPages(GetEndPages)[Self.CurPage - 1]; if liEndPage = nil then Exit; lOldIndex := RMPrinter.PrinterIndex; tmpForm := TRMPageSetupForm.Create(nil); try tmpForm.CurReport := TRMReport(Report); tmpForm.CurPrinter := TRMReport(Report).ReportPrinter; with liEndPage do begin tmpForm.PageSetting.PrinterName := RMPrinters.Printers[RMPrinter.PrinterIndex]; tmpForm.PageSetting.Title := TRMReport(Report).ReportInfo.Title; tmpForm.PageSetting.DoublePass := TRMReport(Report).DoublePass; tmpForm.PageSetting.PrintBackGroundPicture := TRMReport(Report).PrintbackgroundPicture; tmpForm.PageSetting.ColorPrint := TRMReport(Report).ColorPrint; tmpForm.PageSetting.MarginLeft := RMFromMMThousandths(mmMarginLeft, rmutMillimeters); tmpForm.PageSetting.MarginTop := RMFromMMThousandths(mmMarginTop, rmutMillimeters); tmpForm.PageSetting.MarginRight := RMFromMMThousandths(mmMarginRight, rmutMillimeters); tmpForm.PageSetting.MarginBottom := RMFromMMThousandths(mmMarginBottom, rmutMillimeters); tmpForm.PageSetting.PageOr := PageOrientation; tmpForm.PageSetting.PageBin := PageBin; tmpForm.PageSetting.PageSize := PageSize; tmpForm.PageSetting.PageWidth := PageWidth; tmpForm.PageSetting.PageHeight := PageHeight; tmpForm.PageSetting.UnlimitedHeight := True; if tmpForm.PreviewPageSetup then//这里 begin TRMPageSetupForm.FormCloseQuery procedure TRMPageSetupForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean); var liLeft, liTop, liRight, liBottom: Double; liPrnInfo: TRMPageInfo; function dm(pxls: integer; mmInInch: integer): Double; begin Result := Round((pxls / RMInchPerMM / mmInInch) * 10) / 10; end; begin Exit;//这里 退出 if ModalResult = mrOK then begin try FCurPrinter{RMPrinter}.PrinterIndex := cmbPrinterNames.ItemIndex; FCurPrinter{RMPrinter}.SetPrinterInfo(FPageSetting.PageSize, FPageSetting.PageWidth, FPageSetting.PageHeight, FPageSetting.PageBin, FPageSetting.PageOr, False); FCurPrinter{RMPrinter}.FillPrinterInfo(liPrnInfo); liLeft := dm(FCurPrinter{RMPrinter}.PageGutters.Left, FCurPrinter{RMPrinter}.PixelsPerInch.X); liTop := dm(RMPrinter.PageGutters.Top, FCurPrinter{RMPrinter}.PixelsPerInch.Y); liRight := dm(FCurPrinter{RMPrinter}.PageGutters.Right, FCurPrinter{RMPrinter}.PixelsPerInch.X); liBottom := dm(FCurPrinter{RMPrinter}.PageGutters.Bottom, FCurPrinter{RMPrinter}.PixelsPerInch.Y); if (FPageSetting.MarginLeft < liLeft) or (FPageSetting.MarginTop < liTop) or (FPageSetting.MarginRight < liRight) or (FPageSetting.MarginBottom < liBottom) then begin if ((FPageSetting.MarginLeft - liLeft) < 0.01) or ((FPageSetting.MarginTop - liTop) < 0.01) or ((FPageSetting.MarginRight - liRight) < 0.01) or ((FPageSetting.MarginBottom - liBottom) < 0.01) then begin if Application.MessageBox(PChar(RMLoadStr(rmRes + 213)), PChar(RMLoadStr(SWarning)), MB_ICONEXCLAMATION + MB_YESNO) = IDYES then begin if FPageSetting.MarginLeft < liLeft then FPageSetting.MarginLeft := liLeft + 2.5; if FPageSetting.MarginTop < liTop then FPageSetting.MarginTop := liTop + 2.5; if FPageSetting.MarginRight < liRight then FPageSetting.MarginRight := liRight + 2.5; if FPageSetting.MarginBottom < liBottom then FPageSetting.MarginBottom := liBottom + 2.5; end; end; end; except end; end; end;
原文:http://www.cnblogs.com/CodeGear/p/5425203.html