public void PrintCtrl(PrintScale scaling, Rectangle r, PageSettings ps, bool bitmap, bool preview) { _printScale = scaling; _bitmap = bitmap; _printRect = new RectangleF(r.X, r.Y, r.Width, r.Height); try { PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(this.OnPrintCtrl); if (ps != null) { pd.DefaultPageSettings = ps; pd.PrinterSettings = (_printHandler._printSettings == null) ? ps.PrinterSettings : _printHandler.printSettings; } else { pd.DefaultPageSettings = _printHandler.pageSettings; pd.PrinterSettings = (_printHandler._printSettings == null) ? ps.PrinterSettings : _printHandler.printSettings; } DialogResult dr = DialogResult.OK; if (preview) { ChartPrinter.ChartPreviewDialogEx(pd, _printHandler._usePrintDialog); _printHandler._printSettings = pd.PrinterSettings; } else { if (_printHandler._usePrintDialog) { PrintDialog px = new PrintDialog(); px.Document = pd; dr = px.ShowDialog(); px.Dispose(); } if (dr == DialogResult.OK) { pd.Print(); } } pd.Dispose(); } catch (Exception) {} }
public ctrlPrinter(ChartPrinter printHandler, Control ctrl) { _printHandler = printHandler; _ctrl = ctrl; Graphics g = ctrl.CreateGraphics(); _ctrlSize = new SizeF(_ctrl.Size.Width, _ctrl.Size.Height); // the control size needs to be adjusted to normalize the DPI of the console. // for the printer units. _ctrlSize.Width *= 100f / g.DpiX; // _drawFactor.Width; _ctrlSize.Height *= 100f / g.DpiY; // _drawFactor.Height; g.Dispose(); }