/// <summary>
        /// Raises the PageSetup dialog to manage the page settings.
        /// </summary>
        public virtual void PageSetup()
        {
            PageSetupDialog psd = new PageSetupDialog();

            bool isMetric = false;

            try
            {
                RegistryKey key = Registry.CurrentUser;
                key = key.OpenSubKey("Control Panel\\International");
                string s = (string)key.GetValue("iMeasure");
                if (s.Equals("0"))
                {
                    isMetric = true;
                }
            }
            catch
            {
                isMetric = System.Globalization.RegionInfo.CurrentRegion.IsMetric;
            }
            if (isMetric)
            {
                pageSettings.Margins.Left   = (int)(Math.Round(pageSettings.Margins.Left * 2.54));
                pageSettings.Margins.Right  = (int)(Math.Round(pageSettings.Margins.Right * 2.54));
                pageSettings.Margins.Bottom = (int)(Math.Round(pageSettings.Margins.Bottom * 2.54));
                pageSettings.Margins.Top    = (int)(Math.Round(pageSettings.Margins.Top * 2.54));
            }
            //

            psd.PageSettings = pageSettings;
            psd.ShowDialog();

            psd.Dispose();
        }
示例#2
0
        public PageSettings PrtSetUp(PrintDocument printDocument)
        {
            //声明返回值的PageSettings
            PageSettings ps = new PageSettings();
            //申明并实例化PageSetupDialog
            PageSetupDialog psDlg = new PageSetupDialog();

            System.Drawing.Printing.PaperSize size = new System.Drawing.Printing.PaperSize("挂号打印", 472, 276);
            try
            {
                //相关文档及文档页面默认设置
                psDlg.Document               = printDocument;
                psDlg.PageSettings           = printDocument.DefaultPageSettings;
                psDlg.PageSettings.PaperSize = size;
                ps = psDlg.PageSettings;
                printDocument.DefaultPageSettings = psDlg.PageSettings;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "出现打印错误");
            }
            finally
            {
                psDlg.Dispose();
                psDlg = null;
            }
            return(ps);
        }
        private void B_PageSetupDialog_Click(object sender, EventArgs e)
        {
            PageSetupDialog dlg = new PageSetupDialog();

            dlg.Document = new PrintDocument();
            dlg.ShowDialog();
            dlg.Dispose();
        }
示例#4
0
        public void CloseDrawArea()
        {
            //this.SuspendLayout();
            ////
            //// DrawArea
            ////
            //this.Load -= new System.EventHandler(this.DrawArea_Load);
            //this.Paint -= new System.Windows.Forms.PaintEventHandler(this.DrawArea_Paint);
            //this.KeyPress -= new System.Windows.Forms.KeyPressEventHandler(this.DrawArea_KeyPress);
            //this.MouseDoubleClick -= new System.Windows.Forms.MouseEventHandler(this.DrawArea_MouseDoubleClick);
            //this.MouseDown -= new System.Windows.Forms.MouseEventHandler(this.DrawArea_MouseDown);
            //this.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.DrawArea_MouseMove);
            //this.MouseUp -= new System.Windows.Forms.MouseEventHandler(this.DrawArea_MouseUp);
            //this.ResumeLayout(false);
            //_currentPen.Dispose();
            //_currentBrush.Dispose();
            foreach (Control control in this.Controls)
            {
                control.Dispose();
            }

            PageSetupDialog1.Dispose();
            printdoc1.Dispose();
            previewdlg.Dispose();
            PrintDialog1.Dispose();

            if (tempobject != null)
            {
                tempobject.AreaPath.Dispose();
                tempobject.AreaPen.Dispose();
                tempobject.AreaRegion.Dispose();
            }
            //((ToolObject)tools[(int)DrawToolType.Pointer]).m_Cursor.Dispose();
            //((ToolObject)tools[(int)DrawToolType.Rectangle]).m_Cursor.Dispose();
            //((ToolObject)tools[(int)DrawToolType.Ellipse]).m_Cursor.Dispose();
            //((ToolObject)tools[(int)DrawToolType.Line]).m_Cursor.Dispose();
            //((ToolObject)tools[(int)DrawToolType.PolyLine]).m_Cursor.Dispose();
            //((ToolObject)tools[(int)DrawToolType.Text]).m_Cursor.Dispose();
            //((ToolObject)tools[(int)DrawToolType.Image]).m_Cursor.Dispose();
            //((ToolObject)tools[(int)DrawToolType.Variable]).m_Cursor.Dispose();
            //((ToolObject)tools[(int)DrawToolType.Function]).m_Cursor.Dispose();
            //((ToolObject)tools[(int)DrawToolType.FunctionBlock]).m_Cursor.Dispose();
            //((ToolObject)tools[(int)DrawToolType.Wire]).m_Cursor.Dispose();
            //((ToolObject)tools[(int)DrawToolType.Constant]).m_Cursor.Dispose();
        }
示例#5
0
        protected virtual PageSettings ShowPageSetupDialog(System.Drawing.Printing.PrintDocument printDocument_1)
        {
            this.ThrowPrintDocumentNullException(printDocument_1);
            PageSettings    defaultPageSettings = new PageSettings();
            PageSetupDialog dialog = new PageSetupDialog();

            defaultPageSettings = printDocument_1.DefaultPageSettings;
            try
            {
                dialog.Document = printDocument_1;
                Margins margins = printDocument_1.DefaultPageSettings.Margins;
                if (RegionInfo.CurrentRegion.IsMetric)
                {
                    margins = PrinterUnitConvert.Convert(margins, PrinterUnit.Display, PrinterUnit.TenthsOfAMillimeter);
                }
                PageSettings settings2 = (PageSettings)printDocument_1.DefaultPageSettings.Clone();
                dialog.PageSettings         = settings2;
                dialog.PageSettings.Margins = margins;
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    defaultPageSettings = dialog.PageSettings;
                    printDocument_1.DefaultPageSettings = dialog.PageSettings;
                }
            }
            catch (InvalidPrinterException exception)
            {
                this.ShowInvalidPrinterException(exception);
            }
            catch (Exception exception2)
            {
                this.ShowPrinterException(exception2);
            }
            finally
            {
                dialog.Dispose();
                dialog = null;
            }
            return(defaultPageSettings);
        }
示例#6
0
        public static void printUserControl(Form form, string docname, int leftindent, int topindent, int width, int height)
        {
            PageSetupDialog psetup = new PageSetupDialog();

            psetup.PageSettings           = new PageSettings();
            psetup.PrinterSettings        = new PrinterSettings();
            psetup.PageSettings.Landscape = true;
            psetup.PageSettings.Margins   = new Margins(50, 50, 50, 50);
            psetup.ShowNetwork            = false;
            if (psetup.ShowDialog() == DialogResult.OK)
            {
                psetup.Dispose();
                form.TopMost = true;
                form.Update();
                PrintDocument pdoc = new PrintDocument();
                pdoc.PrintPage      += new PrintPageEventHandler(pdoc_PrintPage);
                pdoc.DocumentName    = docname;
                pdoc.PrinterSettings = psetup.PrinterSettings;
                PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
                RECT srcRect;
                //Process proc = new Process();
                //proc.StartInfo.FileName = "notepad.exe";
                //proc.Start();
                //proc.WaitForInputIdle();
                //if (SetForegroundWindow(proc.MainWindowHandle))
                IntPtr handle = form.FindForm().Handle;
                if (SetForegroundWindow(handle))
                {
                    GetWindowRect(handle, out srcRect);
                    //int width = srcRect.Right - srcRect.Left;
                    //int height = srcRect.Bottom - srcRect.Top;

                    memoryImage = new Bitmap(width, height);
                    Graphics screenG = Graphics.FromImage(memoryImage);

                    try
                    {
                        screenG.CopyFromScreen(srcRect.Left + leftindent, srcRect.Top + topindent,
                                               0, 0, new Size(width, height),
                                               CopyPixelOperation.SourceCopy);
                        //bmp.Save("notepad.jpg", ImageFormat.Jpeg);
                        pdoc.PrinterSettings.PrintRange    = psetup.PrinterSettings.PrintRange;
                        pdoc.PrinterSettings.PrinterName   = psetup.PrinterSettings.PrinterName;
                        pdoc.DefaultPageSettings.Landscape = psetup.PageSettings.Landscape;
                        pdoc.DefaultPageSettings.Margins   = psetup.PageSettings.Margins;
                        pdoc.DefaultPageSettings.PaperSize = psetup.PageSettings.PaperSize;
                        printerleftmargin  = psetup.PageSettings.Margins.Left;
                        printerrightmargin = psetup.PageSettings.Margins.Right;


                        /// Starting to work on resizing print images
                        //double PicRatio = width / height;
                        //double printerWidth = pdoc.PrinterSettings.DefaultPageSettings.PrintableArea.Width;
                        //double printerHeight = pdoc.PrinterSettings.DefaultPageSettings.PrintableArea.Height;
                        //double printerRatio = printerWidth / printerHeight;


                        printPreviewDialog1.Document = pdoc;
                        //printPreviewDialog1.SetDesktopLocation(700, 200);
                        printPreviewDialog1.Size = new Size(800, 600);
                        form.TopMost             = false;
                        form.Update();
                        printPreviewDialog1.ShowDialog();

                        //pdoc.Print();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        screenG.Dispose();
                    }
                }
            }
        }