Esempio n. 1
0
        private void SingleDocument_Click(object sender, EventArgs e)
        {
            C1PrintDocument doc = new C1PrintDocument();

            // ensure document can be cancelled:
            doc.DoEvents = true;

            // load into preview:
            this._pview.Document = doc;

            ProgressForm pf = new ProgressForm();

            pf.Show();

            // Build the document:
            try
            {
                FilesPrinter fp = new FilesPrinter();
                fp.MakeMultiDocument(doc, tbDir.Text, tbMask.Text, pf);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            // Reset cancel state of the progress form:
            pf.DialogResult = System.Windows.Forms.DialogResult.None;

            // Set up event handlers for better UI:
            this.FormClosing += (ss, ee) =>
            {
                if (doc.BusyState == BusyStateEnum.Generating)
                {
                    doc.Cancel = true;
                }
            };

            doc.LongOperation += (ss, ee) =>
            {
                pf.SetProgress(string.Format("Generating C1MultiDocument, {0:P} complete...", ee.Complete), (float)ee.Complete);
                if (pf.Cancelled && doc.BusyState == BusyStateEnum.Generating)
                {
                    doc.Cancel = true;
                }
            };

            doc.DocumentEnded += (ss, ee) =>
            {
                pf.Hide();
                this.Activate();
            };

            // Generate the document:
            doc.Generate();
        }
Esempio n. 2
0
        private void MultiDocument_Click(object sender, EventArgs e)
        {
            C1MultiDocument mdoc = new C1MultiDocument();

            // make sure we can cancel the generation:
            mdoc.DoEvents = true;
            // Attach a handler to ItemGenerated to make sure all memory used by a multi-doc
            // item's generation is released when that generation is complete:
            mdoc.ItemGenerated += (ss, ee) =>
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            };

            this._pview.Document = mdoc;

            ProgressForm pf = new ProgressForm();

            pf.Show();

            // Build the multi-document:
            try
            {
                FilesPrinter fp = new FilesPrinter();
                fp.MakeMultiDocument(mdoc, tbDir.Text, tbMask.Text, pf);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            // Reset cancel state of the progress form:
            pf.DialogResult = System.Windows.Forms.DialogResult.None;

            // Set up event handlers for better UI:
            this.FormClosing += (ss, ee) =>
            {
                if (mdoc.BusyState == BusyStateEnum.Generating)
                {
                    mdoc.Cancel = true;
                }
            };

            mdoc.LongOperation += (ss, ee) =>
            {
                pf.SetProgress(string.Format("Generating C1MultiDocument, {0:P} complete...", ee.Complete), (float)ee.Complete);
                if (pf.Cancelled && mdoc.BusyState == BusyStateEnum.Generating)
                {
                    mdoc.Cancel = true;
                }
            };

            mdoc.DocumentEnded += (ss, ee) =>
            {
                pf.Hide();
                this.Activate();
            };

            // Generate the multi-document:
            mdoc.Generate();
        }