打印在C#中重写同一页面

编程入门 行业动态 更新时间:2024-10-26 10:29:51
本文介绍了打印在C#中重写同一页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用PrintDialogue和PrintDocument打印发票。发票详细信息是使用数据网格View.Data网格视图使用for..each语句进行迭代。我已经将e.hasMorePages设置为true.But打印发票重写相同的页面。没有单独的页面。请帮我打印单独的页面。

I am printing invoice using PrintDialogue and PrintDocument. Invoice details are handling using Data Grid View.Data Grid View is iterating using for..each statement.I have already set e.hasMorePages into true.But printing invoice rewriting same pages.Not came in separate pages.Please help me to print in separate pages.

//Printing Starts Here void pdoc_PrintPage(object sender, PrintPageEventArgs e) { // e.HasMorePages = true; Graphics graphics = e.Graphics; Font font = new Font("Courier New", 10); float fontHeight = font.GetHeight(); int startxsupp = 65; int startysupp = 124; int offsetsupp = 40; //-----------------SUPPLIER NAME------------------------------------------------------------------ graphics.DrawString(txtSupp.Text, new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startxsupp, startysupp + offsetsupp); offsetsupp = offsetsupp + 80; //------------------------------------------------------------------------------------------------ //-----------------SUPPLIER ADDRESS--------------------------------------------------------------- int startxsuppadd = 60; graphics.DrawString(txtSuppAddress.Text, new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startxsuppadd, startysupp + offsetsupp); //------------------------------------------------------------- int startX = 660; int startY = 120; int Offset = 40; //-------------------Invoice Details------------------------------------------------------------- graphics.DrawString(txtInvoiceNo.Text, new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 40; string formattedInvDate = dtpInvDate.Value.ToString("dd-MM-yyyy"); graphics.DrawString(formattedInvDate, new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 35; //----------------------------------------------------------------------------------------------- graphics.DrawString(txtDONo.Text.ToString(), new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 35; string formattedDoDate = dtpDOdate.Value.ToString("dd-MM-yyyy"); graphics.DrawString(formattedDoDate, new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 40; //----------------------------------------------------------------------------------------------- graphics.DrawString(txtLPONo.Text.ToString(), new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startX, startY + Offset); Offset = Offset + 40; //---------------------------------------------------------------------------------------------- int startxgrid = 60; int startygrid = 360; int offsetgridy = 40; foreach (DataGridViewRow dr in gridInvDetail.Rows) { if ((dr.Cells["SLNO"].Value ?? string.Empty).ToString() != null) { //---------------------------------------------------------------------------------- string col1 = (dr.Cells["SLNO"].Value ?? string.Empty).ToString(); string col2 = (dr.Cells["DESC"].Value ?? string.Empty).ToString(); string col3 = (dr.Cells["Unit"].Value ?? string.Empty).ToString(); string col4 = (dr.Cells["Quantity"].Value ?? string.Empty).ToString(); string col5 = (dr.Cells["Rate"].Value ?? string.Empty).ToString(); string col6 = (dr.Cells["Amount"].Value ?? string.Empty).ToString(); //--------------------INVOICE ITEMS SERIAL NO--------------------------------------- startxgrid = 30; graphics.DrawString(col1, new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startxgrid, startygrid + offsetgridy); //--------------------INVOICE ITEMS DESCRIPTION------------------------------------ startxgrid = 60; graphics.DrawString(col2, new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startxgrid, startygrid + offsetgridy); //--------------------INVOICE ITEMS UNIT------------------------------------------- startxgrid = 510; graphics.DrawString(col3, new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startxgrid, startygrid + offsetgridy); //--------------------INVOICE ITEMS QTY-------------------------------------------- startxgrid = 590; graphics.DrawString(col4, new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startxgrid, startygrid + offsetgridy); //--------------------INVOICE ITEMS RATE------------------------------------------ startxgrid = 655; graphics.DrawString(string.Format("{0:#,##0.00}", double.Parse(col5)), new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startxgrid, startygrid + offsetgridy); //--------------------INVOICE ITEMS TOTAL------------------------------------------ startxgrid = 750; graphics.DrawString(string.Format("{0:#,##0.00}", double.Parse(col6)), new Font("Courier New", 12, FontStyle.Bold), new SolidBrush(Color.Black), startxgrid, startygrid + offsetgridy); //graphics.DrawString(string.Format((startygrid + offsetgridy).ToString()), // new Font("Courier New", 12, FontStyle.Bold), // new SolidBrush(Color.Black), startxgrid, startygrid + offsetgridy); //---------------------------------------------------------------------------------- offsetgridy = offsetgridy + 20; //---------------------------------------------------------------------------------- if ((startygrid + offsetgridy) > 900) { e.HasMorePages = true; offsetgridy = 40; } } else { break; } } e.HasMorePages = false; }

推荐答案

每页调用一次PrintPage()事件,直到e.HasMorePages为false - 因此任何代码每个页面将执行一次。 您需要在此活动之外指定(并初始化)您的我已打印的内容,否则它将始终继续重置。 参见文章绝对新手的.NET打印指南 [ ^ ] The PrintPage() event is called once per page until the e.HasMorePages is false - therefore any code in that sub will be executed once per page. You need to specify (and initialise) your "what have I already printed" outside of this event otherwise it will always keep resetting. See the article An absolute beginner's guide to printing in .NET[^]

更多推荐

打印在C#中重写同一页面

本文发布于:2023-11-16 20:00:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607254.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   页面

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!