Example #1
0
        private void UpdatePageRange(PrinterSettings ps)
        {
            NumPages = printDocument.GetNumPages(pageSetupDlg.PageSettings);
            int oldMax = ps.MaximumPage;

            ps.MinimumPage = 1;
            ps.MaximumPage = NumPages;
            if (ps.FromPage < 1)
            {
                ps.FromPage = 1;
            }
            if (ps.FromPage > NumPages)
            {
                ps.FromPage = NumPages;
            }

            if (ps.ToPage < 1 || ps.ToPage > NumPages)
            {
                ps.ToPage = NumPages;
            }
            if (ps.ToPage < ps.FromPage)
            {
                ps.ToPage = ps.FromPage;
            }

            if (ps.PrintRange == PrintRange.AllPages ||
                ps.PrintRange == PrintRange.SomePages && oldMax < ps.MaximumPage && ps.ToPage == oldMax && (ps.FromPage == 1 || ps.FromPage != oldMax)) // dialog doesn't show actual number of pages, so we should help user, expanding max range, if it seems user wanted to print all pages up to the end
            {
                ps.ToPage = ps.MaximumPage;
            }
        }
Example #2
0
        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());
                    }
                }
        }