예제 #1
0
        public ReportFormHelper(Form parent, string title, DataGridView report, Action resetTable, string registry, bool saveForm = true)
        {
            this.parent     = parent;
            defaultLocation = new Tuple <int, int>(parent.Top, parent.Left);
            defaultSize     = new Tuple <int, int>(parent.Height, parent.Width);
            PrintTitle      = title;
            ReportGrid      = report;
            _resetTable     = resetTable;
            _registry       = registry;
            _saveForm       = saveForm;

            printDocument = new PrintDocument();
            printDocument.DefaultPageSettings.Landscape = true;
            printDocument.DefaultPageSettings.Margins   = new Margins(15, 15, 15, 15);

            printProvider = PrintingDataGridViewProvider.Create(printDocument, ReportGrid, true, true, true, new TitlePrintBlock(PrintTitle), null, null);

            printDialog = new PrintDialog
            {
                AllowSelection = true,
                AllowSomePages = true,
                Document       = printDocument,
                UseEXDialog    = true
            };

            printPreviewDialog = new PrintPreviewDialog
            {
                AutoScrollMargin  = new Size(0, 0),
                AutoScrollMinSize = new Size(0, 0),
                ClientSize        = new Size(400, 300),
                Document          = printDocument
            };
        }
예제 #2
0
        public static void Print(this DataGridView dgv,
                                 PrintDocument printDocument,
                                 bool printLevelByLevel,
                                 bool centerPage,
                                 bool fitColToPage,
                                 bool showPrintSetDlg,
                                 bool showPreviewDlg,
                                 List <int> toPrintCols,
                                 List <int> toPrintRows
                                 )
        {
            DataGridView dgvToPrint = dgv.Copy(toPrintCols, toPrintRows);

            var printProvider = PrintingDataGridViewProvider.Create(
                printDocument,
                dgvToPrint,
                printLevelByLevel,
                centerPage,
                fitColToPage,
                new TitlePrintBlock()
            {
                ForeColor = Color.DarkBlue,
                Font      = new Font(SystemFonts.CaptionFont.FontFamily, 16),
                Title     = printDocument.DocumentName
            },
                null,
                null);

            bool bContinue = true;

            if (showPrintSetDlg)//显示打印设置对话框
            {
                bContinue = new PrintDialog().ShowDialog() == DialogResult.OK;
            }
            if (bContinue)
            {
                if (showPreviewDlg)//打印预览
                {
                    //printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
                    PrintPreviewDialog previewdlg = new PrintPreviewDialog();
                    previewdlg.ShowIcon = false;
                    previewdlg.Document = printDocument;
                    previewdlg.ShowDialog();
                }
                else
                {
                    printDocument.Print();
                }
            }
        }