當前位置: 首頁>>代碼示例>>C#>>正文


C# Printing.PrintDocument類代碼示例

本文整理匯總了C#中System.Drawing.Printing.PrintDocument的典型用法代碼示例。如果您正苦於以下問題:C# PrintDocument類的具體用法?C# PrintDocument怎麽用?C# PrintDocument使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PrintDocument類屬於System.Drawing.Printing命名空間,在下文中一共展示了PrintDocument類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: PrintClass

 /// <summary>
 /// 打印信息的初始化
 /// </summary>
 /// <param datagrid="DataGridView">打印數據</param>
 /// <param PageS="int">紙張大小</param>
 /// <param lendscape="bool">是否橫向打印</param>
 public PrintClass(DataGridView datagrid, int PageS, bool lendscape)
 {
     this.datagrid = datagrid;//獲取打印數據
     this.PageSheet = PageS;//紙張大小
     printdocument = new PrintDocument();//實例化PrintDocument類
     pagesetupdialog = new PageSetupDialog();//實例化PageSetupDialog類
     pagesetupdialog.Document = printdocument;//獲取當前頁的設置
     printpreviewdialog = new PrintPreviewDialog();//實例化PrintPreviewDialog類
     printpreviewdialog.Document = printdocument;//獲取預覽文檔的信息
     printpreviewdialog.FormBorderStyle = FormBorderStyle.Fixed3D;//設置窗體的邊框樣式
     //橫向打印的設置
     if (PageSheet >= 0)
     {
         if (lendscape == true)
         {
             printdocument.DefaultPageSettings.Landscape = lendscape;//橫向打印
         }
         else
         {
             printdocument.DefaultPageSettings.Landscape = lendscape;//縱向打印
         }
     }
     pagesetupdialog.Document = printdocument;
     printdocument.PrintPage += new PrintPageEventHandler(this.printdocument_printpage);//事件的重載
 }
開發者ID:mahuidong,項目名稱:c-1200-II,代碼行數:31,代碼來源:PrintClass.cs

示例2: bPay_Click

 private void bPay_Click(object sender, EventArgs e)
 {
     DB.Instance.Insert("order", new Parameter("customer_id", cid), new Parameter("dt", DateTime.Now), new Parameter("status", OrderStatus.New));
     uint oid = 0;
     using (MySqlDataReader reader = DB.Instance.SelectReader("select max(id) from order"))
     {
         if(reader != null && reader.Read()){
             oid = reader.GetUInt32(0);
         }
     }
     foreach (var item in Role.Instance.ShopCart)
     {
         DB.Instance.Insert("order_inventory", new Parameter("order_id", oid), new Parameter("inventory_id", item.ID), new Parameter("amount", item.Qty));
     }
     var dr = MessageBox.Show("Order Placed. Would you like to pay now?", "Payment", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     if (dr == DialogResult.Yes)
     {
         new Payment().ShowDialog();
     }
     else if(dr == DialogResult.No)
     {
         var ppd = new PrintPreviewDialog();
         PrintDocument pd = new PrintDocument();
         ppd.Document = pd;
         pd.PrintPage += Pd_PrintPage;
         ppd.ShowDialog();
     }
 }
開發者ID:redlive,項目名稱:csis3275,代碼行數:28,代碼來源:Checkout.cs

示例3: PrintOrder

 public static void PrintOrder()
 {
     var doc = new PrintDocument();
     doc.PrinterSettings.PrinterName = System.Configuration.ConfigurationManager.AppSettings["PrinterName"];
     doc.PrintPage += new PrintPageEventHandler(PrintPage);
     doc.Print();
 }
開發者ID:argetima,項目名稱:Golex,代碼行數:7,代碼來源:Extensions.cs

示例4: OnEndPage

 public override void OnEndPage(
     PrintDocument document,
     PrintPageEventArgs e
     )
 {
     this.OriginController.OnEndPage(document, e);
 }
開發者ID:renyh1013,項目名稱:dp2,代碼行數:7,代碼來源:NewPrintController.cs

示例5: PrintClicked

        private void PrintClicked(object sender, System.EventArgs e)
        {
            if (Viewer == null)
            {
                return;
            }

            PrintDocument pd = new PrintDocument();
            pd.DocumentName = Viewer.SourceFile.LocalPath;
            pd.PrinterSettings.FromPage = 1;
            pd.PrinterSettings.ToPage = Viewer.PageCount;
            pd.PrinterSettings.MaximumPage = Viewer.PageCount;
            pd.PrinterSettings.MinimumPage = 1;
            pd.DefaultPageSettings.Landscape = Viewer.PageWidth > Viewer.PageHeight ? true : false;
            using (PrintDialog dlg = new PrintDialog())
            {
                dlg.Document = pd;
                dlg.AllowSelection = true;
                dlg.AllowSomePages = true;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    Viewer.Print(pd);
                }
            }

        }
開發者ID:myersBR,項目名稱:My-FyiReporting,代碼行數:26,代碼來源:ViewerToolstrip.cs

示例6: Print

        public void Print()
        {
            try {
                _current = 0;

                PrintDocument document = new PrintDocument();
                document.PrinterSettings = _config.PrinterSettings;
                document.PrinterSettings.Collate = true;
                document.PrinterSettings.Copies = (short)_session.NumberOfCopies;
                //document.DefaultPageSettings.Margins = new Margins(100, 100, 100, 100);
                document.DefaultPageSettings.Margins = new Margins(25, 25, 25, 25);
                document.QueryPageSettings += OnQueryPageSettings;
                document.PrintPage += OnPrintPage;

                if (!String.IsNullOrEmpty(_config.PaperSource)) {
                    foreach (PaperSource source in document.PrinterSettings.PaperSources) {
                        if (source.SourceName == _config.PaperSource)
                            document.DefaultPageSettings.PaperSource = source;
                    }
                }

                if (_config.PreviewOnly) {
                    if (Application.OpenForms.Count > 0)
                        Application.OpenForms[0].BeginInvoke(new WaitCallback(PreviewProc), document);
                } else {
                    document.Print();
                }
            } catch (Exception ex) {
            #if DEBUG
                Dicom.Debug.Log.Error("DICOM Print Error: " + ex.ToString());
            #else
                Dicom.Debug.Log.Error("DICOM Print Error: " + ex.Message);
            #endif
            }
        }
開發者ID:k11hao,項目名稱:mdcm-printscp,代碼行數:35,代碼來源:NPrintService.cs

示例7: InitializeComponent

 private void InitializeComponent()
 {
     this.printDocument1 = new System.Drawing.Printing.PrintDocument();
     //
     //Main DataSet Initialization
     //
     this.printPreviewDialog1 = new PrintPreviewDialog();
     this.maindataset = new SupremeTransport.maindataset();
     //
     //Table Adapter Initialization
     //
     this.mainbillTableAdapter = new SupremeTransport.maindatasetTableAdapters.mainbillTableAdapter();
     this.billTableAdapter = new SupremeTransport.maindatasetTableAdapters.billTableAdapter();
     // 
     // printDocument1
     // 
     this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
     // 
     // printPreviewDialog1
     // 
     this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
     this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
     this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
     this.printPreviewDialog1.Enabled = true;
     this.printPreviewDialog1.Name = "printPreviewDialog1";
     this.printPreviewDialog1.Visible = false;
 }
開發者ID:EdiCarlos,項目名稱:MyPractices,代碼行數:27,代碼來源:PrintingClass.cs

示例8: Execute

        public override void Execute()
        {
            printDocument = new PrintDocument();

              printDocument.OriginAtMargins = true;
              printDocument.BeginPrint += new PrintEventHandler(printDocument_BeginPrint);
              printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);

              Dictionary<String, Object> paperSettings = Printing.getPaperSettings(grtArguments);
              printDocument.DefaultPageSettings.Landscape = (string)paperSettings["orientation"] == "landscape";

              // Sizes must be given in inch * 100 (sigh).
              int paperWidth = (int)Math.Round((double)paperSettings["width"] / 0.254);
              int paperHeight = (int)Math.Round((double)paperSettings["height"] / 0.254);
              PaperSize paperSize = new PaperSize("Doesn't matter", paperWidth, paperHeight);
              printDocument.DefaultPageSettings.PaperSize = paperSize;

              if ((bool)paperSettings["marginsSet"])
            printDocument.DefaultPageSettings.Margins =
              new Margins((int)paperSettings["marginLeft"], (int)paperSettings["marginRight"],
            (int)paperSettings["marginTop"], (int)paperSettings["marginBottom"]);

              printDialog = new System.Windows.Forms.PrintDialog();
              printDialog.Document = printDocument;
              printDialog.AllowPrintToFile = true;

              pageNumber = 0;
              pageCount = -1;

              if (printDialog.ShowDialog() == DialogResult.OK)
              {
            printDocument.Print();
              }
        }
開發者ID:abibell,項目名稱:mysql-workbench,代碼行數:34,代碼來源:PrintDialog.cs

示例9: OnStartPrint

        public override void OnStartPrint(PrintDocument document, PrintEventArgs e) {
            Debug.Assert(dc == null && graphics == null, "PrintController methods called in the wrong order?");

            // For security purposes, don't assume our public methods methods are called in any particular order
            CheckSecurity(document);

            base.OnStartPrint(document, e);
            // the win32 methods below SuppressUnmanagedCodeAttributes so assertin on UnmanagedCodePermission is redundant
            if (!document.PrinterSettings.IsValid)
                throw new InvalidPrinterException(document.PrinterSettings);

            dc = document.PrinterSettings.CreateDeviceContext(modeHandle);
            SafeNativeMethods.DOCINFO info = new SafeNativeMethods.DOCINFO();
            info.lpszDocName = document.DocumentName;
            if (document.PrinterSettings.PrintToFile)
                info.lpszOutput = document.PrinterSettings.OutputPort; //This will be "FILE:"
            else
                info.lpszOutput = null;
            info.lpszDatatype = null;
            info.fwType = 0;

            int result = SafeNativeMethods.StartDoc(new HandleRef(this.dc, dc.Hdc), info);
            if (result <= 0) {
                int error = Marshal.GetLastWin32Error();
                if (error == SafeNativeMethods.ERROR_CANCELLED) {
                    e.Cancel = true;
                }
                else {
                    throw new Win32Exception(error);
                }
            }
        }
開發者ID:JianwenSun,項目名稱:cc,代碼行數:32,代碼來源:DefaultPrintController.cs

示例10: Print_button_Click

 /* Events to execute when the "Print" button is clicked */
 private void Print_button_Click(object sender, EventArgs e)
 {
     /* Creates a new instance of printDocument, appends the result from PrintDocumentOnPrintPage and prints the result */
     PrintDocument printDocument = new PrintDocument();
     printDocument.PrintPage += PrintDocumentOnPrintPage;
     printDocument.Print();
 }
開發者ID:Nicolai-,項目名稱:CSharp_Mail_Client_New,代碼行數:8,代碼來源:ShowMail.cs

示例11: axWindowsMediaPlayer1_PlayStateChange

        private void axWindowsMediaPlayer1_PlayStateChange(object sender, _WMPOCXEvents_PlayStateChangeEvent e)
        {
            //QUANDO VIDEO FOR PARADO
            if (  axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPaused )
            {
                //O VIDEO FOI PARADO, PARA CONTINUAR PRECISA CLICAR EM OK
                if ( MessageBox.Show("Video Parado. Clique aqui para continuar!", "",
                    MessageBoxButtons.OK , MessageBoxIcon.Information) == DialogResult.OK )
                {
                    axWindowsMediaPlayer1.Ctlcontrols.play();
                }
            }

            //QUANDO O VIDEO ACABAR
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
            {
                //IMPRIME
                PrintDocument document = new PrintDocument();
                document.PrintPage += new PrintPageEventHandler(impressaoConf);
                document.Print();

                this.Hide();

            }
        }
開發者ID:marcommas,項目名稱:videoAlstomCSharp,代碼行數:25,代碼來源:Login.cs

示例12: Imprimir

        public static void Imprimir(Entidades.Álbum.Álbum álbum, ItensImpressão itens)
        {
            using (PrintDocument documento = new PrintDocument())
            {
                documento.DocumentName = "Álbum " + álbum.Nome;

                using (PrintDialog dlg = new PrintDialog())
                {
                    dlg.AllowCurrentPage = false;
                    dlg.AllowSelection = false;
                    dlg.AllowSomePages = true;
                    dlg.UseEXDialog = true;
                    dlg.Document = documento;

                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        ControleImpressão ctrl = new ControleImpressão(álbum, itens);

                        ctrl.página = new Página(
                                documento.PrinterSettings.DefaultPageSettings.PrintableArea.Width / 100f,
                                documento.PrinterSettings.DefaultPageSettings.PrintableArea.Height / 100f,
                                4, 5);
            
                        ctrl.daPágina = dlg.PrinterSettings.FromPage;
                        ctrl.atéPágina = dlg.PrinterSettings.ToPage != 0 ?
                            dlg.PrinterSettings.ToPage : int.MaxValue;

                        documento.PrintPage += new PrintPageEventHandler(ctrl.ImprimirPágina);
                        documento.Print();
                    }
                }
            }
        }
開發者ID:andrepontesmelo,項目名稱:imjoias,代碼行數:33,代碼來源:ControleImpressão.cs

示例13: button1_Click

 private void button1_Click(object sender, EventArgs e)
 {
     PrintDocument pd = new PrintDocument();
         pd.PrintPage += PrintPage;
         pd.Print();
         this.Close();
 }
開發者ID:vivektarwan,項目名稱:JSSRISf,代碼行數:7,代碼來源:Printpatientinfo.cs

示例14: createXmlApp

        //如下的這個方法可以注釋掉,沒有任何的作用
        public void createXmlApp()
        {
            // 首先創建文件
            FileStream fs = File.Create(Application.StartupPath + "\\xmlAPP.xml");
            fs.Close();//關閉文件

            //創建 XmlDocument 以便操作
            XmlDocument xmlDoc = new XmlDocument();

            //xml 唯一的根,我設置的根都是root
            XmlElement xmlEleRoot = xmlDoc.CreateElement("root");

            // 這個配置還有一個是必須的,就是打印機的DPI, 其他的都不是必要的
            XmlElement xmlElePrinter = xmlDoc.CreateElement("printer");

            //打印機名稱,這裏直接設置默認打印機
            PrintDocument printDoc = new PrintDocument();
            xmlElePrinter.SetAttribute("PrinterName", printDoc.PrinterSettings.PrinterName);
            printDoc.Dispose();//釋放資源

            //DPI有兩個
            xmlElePrinter.SetAttribute("DPIX", "600");
            xmlElePrinter.SetAttribute("DPIY", "600");

            //如下是兩個添加操作了
            xmlEleRoot.AppendChild(xmlElePrinter);
            xmlDoc.AppendChild(xmlEleRoot);

            //保存操作
            xmlDoc.Save(Application.StartupPath + "\\xmlAPP.xml");
        }
開發者ID:kerwinxu,項目名稱:barcodeManager,代碼行數:32,代碼來源:ClsXmlAPP.cs

示例15: butPrint_Click

		private void butPrint_Click(object sender,EventArgs e) {
			PrintDocument pd2=new PrintDocument();
			pd2.PrintPage+=new PrintPageEventHandler(this.pd2_PrintPage);
			pd2.OriginAtMargins=true;
			pd2.DefaultPageSettings.Margins=new Margins(0,0,0,0);
			pd2.Print();
		}
開發者ID:romeroyonatan,項目名稱:opendental,代碼行數:7,代碼來源:FormPerioTest.cs


注:本文中的System.Drawing.Printing.PrintDocument類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。