/// <summary>
        /// displays options dialog (if not disabled via settings) and windows
        /// print dialog.
        /// </summary>
        /// <returns>printer settings if actually printed, or null if print was cancelled or has failed</returns>
        public PrinterSettings PrintWithDialog()
        {
            PrinterSettings returnPrinterSettings = null;

            if (printDialog.ShowDialog() == DialogResult.OK)
            {
                bool cancelled = false;
                if (conf.OutputPrintPromptOptions)
                {
                    using (PrintOptionsDialog printOptionsDialog = new PrintOptionsDialog()) {
                        DialogResult result = printOptionsDialog.ShowDialog();
                        if (result != DialogResult.OK)
                        {
                            cancelled = true;
                        }
                    }
                }
                try {
                    if (!cancelled)
                    {
                        printDocument.Print();
                        returnPrinterSettings = printDialog.PrinterSettings;
                    }
                } catch (Exception e) {
                    LOG.Error("An error ocurred while trying to print", e);
                    MessageBox.Show(Language.GetString(LangKey.print_error), Language.GetString(LangKey.error));
                }
            }
            image.Dispose();
            image = null;
            return(returnPrinterSettings);
        }
예제 #2
0
 /**
  * This Dispose is called from the Dispose and the Destructor.
  * When disposing==true all non-managed resources should be freed too!
  */
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (image != null)
         {
             image.Dispose();
         }
         if (printDocument != null)
         {
             printDocument.Dispose();
         }
         if (printDialog != null)
         {
             printDialog.Dispose();
         }
         if (printOptionsDialog != null)
         {
             printOptionsDialog.Dispose();
         }
     }
     image              = null;
     printDocument      = null;
     printDialog        = null;
     printOptionsDialog = null;
 }
예제 #3
0
        /// <summary>
        /// Main method
        /// </summary>
        private void PrintPlan()
        {
            using (PrintDocument doc = new PrintDocument())
            {
                doc.DocumentName = $"Skill Plan for {m_character.Name} ({m_plan.Name})";
                doc.PrintPage   += doc_PrintPage;

                //Display the options
                using (PrintOptionsDialog prdlg = new PrintOptionsDialog(m_settings, doc))
                {
                    if (prdlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    doc.PrinterSettings.PrinterName = prdlg.PrinterName;

                    // Display the preview
                    using (PrintPreviewDialog pd = new PrintPreviewDialog())
                    {
                        pd.Document = doc;
                        pd.ShowDialog();
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// display print options dialog (if the user has not configured Greenshot not to)
        /// </summary>
        /// <returns>result of the print dialog, or null if the dialog has not been displayed by config</returns>
        private DialogResult?ShowPrintOptionsDialog()
        {
            DialogResult?ret = null;

            if (conf.OutputPrintPromptOptions)
            {
                using (PrintOptionsDialog printOptionsDialog = new PrintOptionsDialog()) {
                    ret = printOptionsDialog.ShowDialog();
                }
            }
            return(ret);
        }
        void GetImageForPrint(object sender, PrintPageEventArgs e)
        {
            PrintOptionsDialog pod = new PrintOptionsDialog();

            pod.ShowDialog();

            ContentAlignment alignment = pod.AllowPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;

            RectangleF   pageRect  = e.PageSettings.PrintableArea;
            GraphicsUnit gu        = GraphicsUnit.Pixel;
            RectangleF   imageRect = image.GetBounds(ref gu);

            // rotate the image if it fits the page better
            if (pod.AllowPrintRotate)
            {
                if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) ||
                    (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height))
                {
                    image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    imageRect = image.GetBounds(ref gu);
                    if (alignment.Equals(ContentAlignment.TopLeft))
                    {
                        alignment = ContentAlignment.TopRight;
                    }
                }
            }
            RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height);;

            // scale the image to fit the page better
            if (pod.AllowPrintEnlarge || pod.AllowPrintShrink)
            {
                SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, false);
                if ((pod.AllowPrintShrink && resizedRect.Width < printRect.Width) ||
                    pod.AllowPrintEnlarge && resizedRect.Width > printRect.Width)
                {
                    printRect.Size = resizedRect;
                }
            }
            // align the image
            printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Width, pageRect.Height), alignment);

            e.Graphics.DrawImage(image, printRect, imageRect, GraphicsUnit.Pixel);
        }
예제 #6
0
        /// <summary>
        /// Main method
        /// </summary>
        private void PrintPlan()
        {
            PrintDocument doc = new PrintDocument();

            doc.DocumentName = String.Format(CultureConstants.DefaultCulture, "Skill Plan for {0} ({1})", m_character.Name, m_plan.Name);
            doc.PrintPage   += doc_PrintPage;

            //Display the options
            using (PrintOptionsDialog prdlg = new PrintOptionsDialog(m_settings, doc))
            {
                if (prdlg.ShowDialog() == DialogResult.OK)
                {
                    doc.PrinterSettings.PrinterName = prdlg.PrinterName;

                    // Display the preview
                    using (PrintPreviewDialog pd = new PrintPreviewDialog())
                    {
                        pd.Document = doc;
                        pd.ShowDialog();
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Main method
        /// </summary>
        private void PrintPlan()
        {
            PrintDocument doc = new PrintDocument();

            doc.DocumentName = "Skill Plan for " + m_character.Name + " (" + m_plan.Name + ")";
            doc.PrintPage   += new PrintPageEventHandler(doc_PrintPage);

            //Display the options
            using (PrintOptionsDialog prdlg = new PrintOptionsDialog(m_settings, doc))
            {
                if (prdlg.ShowDialog() == DialogResult.OK)
                {
                    doc.PrinterSettings.PrinterName = prdlg.PrinterName;

                    // Display the preview
                    using (PrintPreviewDialog pd = new PrintPreviewDialog())
                    {
                        pd.Document = doc;
                        pd.ShowDialog();
                    }
                }
            }
        }
예제 #8
0
        void DrawImageForPrint(object sender, PrintPageEventArgs e)
        {
            PrintOptionsDialog pod = printOptionsDialog;

            ContentAlignment alignment = pod.AllowPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;

            if (conf.OutputPrintInverted)
            {
                // Invert Bitmap
                BitmapBuffer bb = new BitmapBuffer((Bitmap)image, false);
                bb.Lock();
                for (int y = 0; y < bb.Height; y++)
                {
                    for (int x = 0; x < bb.Width; x++)
                    {
                        Color color         = bb.GetColorAt(x, y);
                        Color invertedColor = Color.FromArgb(color.A, color.R ^ 255, color.G ^ 255, color.B ^ 255);
                        bb.SetColorAt(x, y, invertedColor);
                    }
                }
                bb.Dispose();
            }

            RectangleF   pageRect  = e.PageSettings.PrintableArea;
            GraphicsUnit gu        = GraphicsUnit.Pixel;
            RectangleF   imageRect = image.GetBounds(ref gu);

            // rotate the image if it fits the page better
            if (pod.AllowPrintRotate)
            {
                if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) ||
                    (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height))
                {
                    image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    imageRect = image.GetBounds(ref gu);
                    if (alignment.Equals(ContentAlignment.TopLeft))
                    {
                        alignment = ContentAlignment.TopRight;
                    }
                }
            }
            RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height);;

            // scale the image to fit the page better
            if (pod.AllowPrintEnlarge || pod.AllowPrintShrink)
            {
                SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, false);
                if ((pod.AllowPrintShrink && resizedRect.Width < printRect.Width) ||
                    pod.AllowPrintEnlarge && resizedRect.Width > printRect.Width)
                {
                    printRect.Size = resizedRect;
                }
            }

            // prepare timestamp
            float dateStringWidth  = 0;
            float dateStringHeight = 0;

            if (conf.OutputPrintTimestamp)
            {
                Font   f          = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular);
                string dateString = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
                dateStringWidth  = e.Graphics.MeasureString(dateString, f).Width;
                dateStringHeight = e.Graphics.MeasureString(dateString, f).Height;
                e.Graphics.DrawString(dateString, f, Brushes.Black, pageRect.Width / 2 - (dateStringWidth / 2), pageRect.Height - dateStringHeight);
            }

            // align the image
            printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Width, pageRect.Height - dateStringHeight * 2), alignment);

            e.Graphics.DrawImage(image, printRect, imageRect, GraphicsUnit.Pixel);
        }