private void PreviewWinForms2_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (fmetapr != null)
     {
         try
         {
             fmetapr.Dispose();
         }
         finally
         {
             fmetapr = null;
         }
     }
 }
Beispiel #2
0
 public void DoDispose()
 {
     if (fmetapr != null)
     {
         try
         {
             fmetapr.Dispose();
             fmetapr = null;
         }
         finally
         {
             fmetapr = null;
         }
     }
 }
        /// <summary>
        /// Process a MetaFile, printing or previewing
        /// </summary>
        /// <param name="meta">MetaFile to print</param>
        override public bool Print(MetaFile meta)
        {
            overridedriver = null;
            DrawFound      = (FPreview && (!SystemPreview));

            if (!FPreview)
            {
                // Get printer data so it can be a dot matrix print option
                string drivername = PrinterConfig.GetDriverName(meta.PrinterSelect);
                if (drivername.Length > 0)
                {
                    using (PrintOutText ntextdriver = new PrintOutText())
                    {
                        ntextdriver.ForceDriverName = drivername;
                        overridedriver = ntextdriver;
                        if (PreparePrint(meta))
                        {
                            bool doprint = true;
                            if (ShowPrintDialog)
                            {
                                using (PrintDialog pdia = new PrintDialog())
                                {
                                    pdia.ShowHelp       = true;
                                    pdia.ShowNetwork    = true;
                                    pdia.AllowSomePages = true;
                                    // bug from Microsoft not showing dialog
                                    pdia.UseEXDialog = true;
                                    pdia.Document    = doc;
                                    DialogResult aresult = pdia.ShowDialog();
                                    doprint = aresult == DialogResult.OK;
                                }
                            }
                            if (doprint)
                            {
                                ntextdriver.Print(meta);
                                NewDocument(meta);

                                string atext = ntextdriver.PrintResult.ToString();
                                //MessageBox.Show("Blank lines:"+ntextdriver.blanklines.ToString());
                                if (atext.Length > 0)
                                {
                                    FBlackLines = FBlackLines + ntextdriver.blacklines;
                                    FWhiteLines = FWhiteLines + ntextdriver.whitelines;

                                    RawPrinterHelper.SendStringToPrinter(doc.PrinterSettings.PrinterName, atext);
                                    return(true);
                                }
                                EndDocument(meta);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }
            }



            bool            nresult         = false;
            WMFOptimization oldoptimization = OptimizeWMF;

            try
            {
                DisableForwardOnly = false;
                if (!Preview)
                {
                    OptimizeWMF = WMFOptimization.None;
                }
                else
                {
                    // For preview, the metafile must save all pages
                    if (!SystemPreview)
                    {
                        DisableForwardOnly = true;
                    }
                }
                if (PreparePrint(meta))
                {
                    bool doprint = true;
                    if (ShowPrintDialog)
                    {
                        using (PrintDialog pdia = new PrintDialog())
                        {
                            // Bug from microsft not showing dialog in 64bit machines
                            pdia.UseEXDialog    = true;
                            pdia.ShowHelp       = true;
                            pdia.ShowNetwork    = true;
                            pdia.AllowSomePages = true;
                            pdia.Document       = doc;
                            DialogResult aresult = pdia.ShowDialog();
                            doprint = aresult == DialogResult.OK;
                        }
                    }
                    if (doprint)
                    {
                        if (!Preview)
                        {
                            meta.ForwardOnly = true;
                            try
                            {
                                doc.Print();
                            }
                            catch (Exception E)
                            {
                                string printername = doc.PrinterSettings.PrinterName;
                                throw new Exception("Printer error: " + printername + " " + E.Message);
                            }
                        }
                        else
                        {
#if REPMAN_NOPREVIEW
                            throw new Exception("Feature PrintPreviewDialog not supported");
#else
                            if (SystemPreview)
                            {
                                using (PrintPreviewDialog previewdia = new PrintPreviewDialog())
                                {
                                    previewdia.Document = doc;
                                    previewdia.ShowDialog();
                                }
                            }
                            else
                            {
                                if (previewmetafile != null)
                                {
                                    previewmetafile.Dispose();
                                    previewmetafile = null;
                                }
                                previewmetafile = new PreviewMetaFile();
                                SetReportEvents();
                                previewmetafile.OptimizeWMF = OptimizeWMF;
                                previewmetafile.MetaFile    = meta;
                                previewmetafile.SetDriver(this);
                                PreviewWindow.WindowMode    = WindowMode;
                                PreviewWindow.ShowInTaskbar = ShowInTaskbar;
                                PreviewWindow.LargeButtons  = LargeButtons;
                                PreviewWindow.PreviewReport(previewmetafile);
                            }
#endif
                        }
                        nresult = true;
                    }
                }
            }
            finally
            {
                OptimizeWMF = oldoptimization;
            }
            return(nresult);
        }