private bool PrintLoop(PrintDocument document)
        {
            PrintPageEventArgs         args2;
            QueryPageSettingsEventArgs e = new QueryPageSettingsEventArgs((PageSettings)document.DefaultPageSettings.Clone());

            do
            {
                document._OnQueryPageSettings(e);
                if (e.Cancel)
                {
                    return(true);
                }
                args2 = this.CreatePrintPageEvent(e.PageSettings);
                Graphics graphics = this.OnStartPage(document, args2);
                args2.SetGraphics(graphics);
                try
                {
                    document._OnPrintPage(args2);
                    this.OnEndPage(document, args2);
                }
                finally
                {
                    args2.Dispose();
                }
                if (args2.Cancel)
                {
                    return(true);
                }
            }while (args2.HasMorePages);
            return(false);
        }
Ejemplo n.º 2
0
        private bool PrintLoopOptimized(PrintDocument document)
        {
            PrintPageEventArgs         pageEvent            = null;
            PageSettings               documentPageSettings = (PageSettings)document.DefaultPageSettings.Clone();
            QueryPageSettingsEventArgs queryEvent           = new QueryPageSettingsEventArgs(documentPageSettings);

            for (;;)
            {
                queryEvent.PageSettingsChanged = false;
                document._OnQueryPageSettings(queryEvent);
                if (queryEvent.Cancel)
                {
                    return(true);
                }

                if (!queryEvent.PageSettingsChanged)
                {
                    // QueryPageSettings event handler did not change the page settings,
                    // thus we use default page settings from the document object.
                    if (pageEvent == null)
                    {
                        pageEvent = CreatePrintPageEvent(queryEvent.PageSettings);
                    }
                    else
                    {
                        // This is not the first page and the settings had not changed since the previous page,
                        // thus don't re-apply them.
                        pageEvent.CopySettingsToDevMode = false;
                    }

                    Graphics graphics = OnStartPage(document, pageEvent);
                    pageEvent.SetGraphics(graphics);
                }
                else
                {
                    // Page settings were customized, so use the customized ones in the start page event.
                    pageEvent = CreatePrintPageEvent(queryEvent.PageSettings);
                    Graphics graphics = OnStartPage(document, pageEvent);
                    pageEvent.SetGraphics(graphics);
                }

                try {
                    document._OnPrintPage(pageEvent);
                    OnEndPage(document, pageEvent);
                }
                finally {
                    pageEvent.Graphics.Dispose();
                    pageEvent.SetGraphics(null);
                }

                if (pageEvent.Cancel)
                {
                    return(true);
                }
                else if (!pageEvent.HasMorePages)
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 3
0
        // Returns true if print was aborted.
        // WARNING: if you have nested PrintControllers, this method won't get called on the inner one
        // Add initialization code to StartPrint or StartPage instead.
        private bool PrintLoop(PrintDocument document)
        {
            QueryPageSettingsEventArgs queryEvent = new QueryPageSettingsEventArgs((PageSettings)document.DefaultPageSettings.Clone());

            for (;;)
            {
                document._OnQueryPageSettings(queryEvent);
                if (queryEvent.Cancel)
                {
                    return(true);
                }

                PrintPageEventArgs pageEvent = CreatePrintPageEvent(queryEvent.PageSettings);
                Graphics           graphics  = OnStartPage(document, pageEvent);
                pageEvent.SetGraphics(graphics);

                try
                {
                    document._OnPrintPage(pageEvent);
                    OnEndPage(document, pageEvent);
                }
                finally
                {
                    pageEvent.Dispose();
                }

                if (pageEvent.Cancel)
                {
                    return(true);
                }
                else if (!pageEvent.HasMorePages)
                {
                    return(false);
                }
                else
                {
                    // loop
                }
            }
        }
 private bool PrintLoop(PrintDocument document)
 {
     PrintPageEventArgs args2;
     QueryPageSettingsEventArgs e = new QueryPageSettingsEventArgs((PageSettings) document.DefaultPageSettings.Clone());
     do
     {
         document._OnQueryPageSettings(e);
         if (e.Cancel)
         {
             return true;
         }
         args2 = this.CreatePrintPageEvent(e.PageSettings);
         Graphics graphics = this.OnStartPage(document, args2);
         args2.SetGraphics(graphics);
         try
         {
             document._OnPrintPage(args2);
             this.OnEndPage(document, args2);
         }
         finally
         {
             args2.Dispose();
         }
         if (args2.Cancel)
         {
             return true;
         }
     }
     while (args2.HasMorePages);
     return false;
 }
Ejemplo n.º 5
0
        // Returns true if print was aborted.
        // WARNING: if you have nested PrintControllers, this method won't get called on the inner one
        // Add initialization code to StartPrint or StartPage instead.
        private bool PrintLoop(PrintDocument document) {
            QueryPageSettingsEventArgs queryEvent = new QueryPageSettingsEventArgs((PageSettings) document.DefaultPageSettings.Clone());
            for (;;) {
                document._OnQueryPageSettings(queryEvent);
                if (queryEvent.Cancel) {
                    return true;
                }

                PrintPageEventArgs pageEvent = CreatePrintPageEvent(queryEvent.PageSettings);
                Graphics graphics = OnStartPage(document, pageEvent);
                pageEvent.SetGraphics(graphics);

                try {
                    document._OnPrintPage(pageEvent);
                    OnEndPage(document, pageEvent);
                }
                finally {
                    pageEvent.Dispose();
                }

                if (pageEvent.Cancel) {
                    return true;
                }
                else if (!pageEvent.HasMorePages) {
                    return false;
                }
                else {
                    // loop
                }
            }
        }