private void pictureBox1_Paint(object sender, PaintEventArgs e) { var im = printDocument.Image; if (im == null) { return; } // pages var k = ScaleK; var clipRec = new RectangleF(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height); var bRect = new RectangleF(0, 0, pictureBox1.Width, pictureBox1.Height); Dictionary <int, RectangleF> rects = new Dictionary <int, RectangleF>(); for (int i = 0, n = NumPages; i < n; i++) { var rf = DocCoord2ViewCoord(printDocument.GetSrcRect(i, PageSize), k); if (rf.IntersectsWith(clipRec)) { rects.Add(i, RectangleF.Intersect(bRect, rf)); } } using (var pen = new Pen(Color.Blue, 2)) { if (rects.Any()) { DrawPages(e.Graphics, rects, pen); } // selection pen.Width = 1; pen.Color = Color.Black; pen.DashStyle = DashStyle.Dash; if (selection != null && !selection.IsEmpty) { e.Graphics.DrawRectangle(pen, selection); } } }
public void Test() { using (var bm = new Bitmap(2000, 1000)) using (var pd = new MapPrintDocument()) { bm.SetResolution(150, 150); pd.SetImage(bm); pd.PrintArea = new Rectangle(300, 0, 1700, 1000); var pageSize = new Size(900, 1300); int n = pd.GetNumPages(pageSize); sb.AppendLine("pages: " + n.ToString()); for (int i = 0; i < n; i++) { var r = pd.GetSrcRect(i, pageSize); sb.AppendLine("page " + i.ToString() + ": " + r.ToString()); } } }