我需要进行多页打印. [英] I need to do multipage printing.

查看:72
本文介绍了我需要进行多页打印.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要进行多页打印.但是,它只打印一页.我怎么解决这个问题?请检查我的代码,并让我知道我做错了.

I need to do multipage print. However, it only print one page. How can I solve this problem? Please check my code and let me know which i made mistake.

private void Print_Form(DataSet dsPRTSET)
{
   dsPRTDB = dsPRTSET;
   PrintDocument pfDoc = new PrintDocument();
   PrintPreviewDialog prPRVVIEW = new PrintPreviewDialog();
   pfDoc.DefaultPageSettings.Landscape = false;
   pfDoc.DefaultPageSettings.PaperSize = new PaperSize("PaperLetter", 850, 1100);
   pfDoc.PrintPage += new PrintPageEventHandler(this.PF_PRINTPAGE);
   prPRVVIEW.Document = pfDoc;
   prPRVVIEW.Show();
}
private void PF_PRINTPAGE(object sender, PrintPageEventArgs e)
{
   float nprLines = 0;
   float nYPos = 0;
   float nTopMargin = e.MarginBounds.Top;
   float nLeftMargin = e.MarginBounds.Left;
   Font prtFont = new Font("Courier New",10);
   nprLines = e.MarginBounds.Height / prtFont.GetHeight(e.Graphics);
   string cTMVAL = "";
   Brush MyBrush = new SolidBrush(Color.Black);
   System.Drawing.Font MyFont = new System.Drawing.Font("Courier New", 10);
   Pen MyPen = new Pen(MyBrush, 0.1F);
   e.Graphics.PageUnit = System.Drawing.GraphicsUnit.Millimeter;
   Graphics prtG = e.Graphics;

   string cSEASON = "";
   if (opnSEASON1.Checked == true)
   {
      cSEASON = "부활";
   }
   else
   {
      cSEASON = "성탄";
   }

   int ml = 0;
   int cl = 0;
   for (ml = 0; ml <= dsPRTDB.Tables[0].Rows.Count - 1; ml++)
   {
      switch (cl)
      {
         case 0:
         case 2:
         case 4:
            if (cl == 0)
            {
               cTMVAL = txtYEAR.Text + " 년 " + cSEASON + " 판공성사표";
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 20F);
               cTMVAL = "NO: " + dsPRTDB.Tables[0].Rows[ml]["PP_NO"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 25F);
               cTMVAL = "이름: " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_HNAME"].ToString() +
                        "(" +
                        dsPRTDB.Tables[0].Rows[ml]["PP_FNAME"].ToString() + " " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_LNAME"].ToString() + ")";
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 35F);
               cTMVAL = "세례명: " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_SNAME"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 40F);
               cTMVAL = "구역/반 -> " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_KUYOUK"].ToString() + "/" +
                        dsPRTDB.Tables[0].Rows[ml]["PP_BAN"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 45F);
            }
            else if (cl == 2)
            {
               cTMVAL = txtYEAR.Text + " 년 " + cSEASON + " 판공성사표";
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 85F);
               cTMVAL = "NO: " + dsPRTDB.Tables[0].Rows[ml]["PP_NO"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 90F);
               cTMVAL = "이름: " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_HNAME"].ToString() +
                        "(" +
                        dsPRTDB.Tables[0].Rows[ml]["PP_FNAME"].ToString() + " " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_LNAME"].ToString() + ")";
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 100F);
               cTMVAL = "세례명: " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_SNAME"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 105F);
               cTMVAL = "구역/반 -> " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_KUYOUK"].ToString() + "/" +
                        dsPRTDB.Tables[0].Rows[ml]["PP_BAN"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 110F);
            }
            else
            {
               cTMVAL = txtYEAR.Text + " 년 " + cSEASON + " 판공성사표";
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 140F);
               cTMVAL = "NO: " + dsPRTDB.Tables[0].Rows[ml]["PP_NO"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 145F);
               cTMVAL = "이름: " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_HNAME"].ToString() +
                        "(" +
                        dsPRTDB.Tables[0].Rows[ml]["PP_FNAME"].ToString() + " " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_LNAME"].ToString() + ")";
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 155F);
               cTMVAL = "세례명: " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_SNAME"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 160F);
               cTMVAL = "구역/반 -> " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_KUYOUK"].ToString() + "/" +
                        dsPRTDB.Tables[0].Rows[ml]["PP_BAN"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 13F, nYPos + 165F);
            }
            break;
         case 1:
         case 3:
         case 5:
            if (cl == 1)
            {
               cTMVAL = txtYEAR.Text + " 년 " + cSEASON + " 판공성사표";
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 20F);
               cTMVAL = "NO: " + dsPRTDB.Tables[0].Rows[ml]["PP_NO"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 25F);
               cTMVAL = "이름: " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_HNAME"].ToString() +
                        "(" +
                        dsPRTDB.Tables[0].Rows[ml]["PP_FNAME"].ToString() + " " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_LNAME"].ToString() + ")";
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 35F);
               cTMVAL = "세례명: " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_SNAME"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 40F);
               cTMVAL = "구역/반 -> " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_KUYOUK"].ToString() + "/" +
                        dsPRTDB.Tables[0].Rows[ml]["PP_BAN"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 45F);
            }
            else if (cl == 3)
            {
               cTMVAL = txtYEAR.Text + " 년 " + cSEASON + " 판공성사표";
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 85F);
               cTMVAL = "NO: " + dsPRTDB.Tables[0].Rows[ml]["PP_NO"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 90F);
               cTMVAL = "이름: " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_HNAME"].ToString() +
                        "(" +
                        dsPRTDB.Tables[0].Rows[ml]["PP_FNAME"].ToString() + " " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_LNAME"].ToString() + ")";
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 100F);
               cTMVAL = "세례명: " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_SNAME"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 105F);
               cTMVAL = "구역/반 -> " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_KUYOUK"].ToString() + "/" +
                        dsPRTDB.Tables[0].Rows[ml]["PP_BAN"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 110F);
            }
            else
            {
               cTMVAL = txtYEAR.Text + " 년 " + cSEASON + " 판공성사표";
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 140F);
               cTMVAL = "NO: " + dsPRTDB.Tables[0].Rows[ml]["PP_NO"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 145F);
               cTMVAL = "이름: " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_HNAME"].ToString() +
                        "(" +
                        dsPRTDB.Tables[0].Rows[ml]["PP_FNAME"].ToString() + " " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_LNAME"].ToString() + ")";
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 155F);
               cTMVAL = "세례명: " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_SNAME"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 160F);
               cTMVAL = "구역/반 -> " +
                        dsPRTDB.Tables[0].Rows[ml]["PP_KUYOUK"].ToString() + "/" +
                        dsPRTDB.Tables[0].Rows[ml]["PP_BAN"].ToString();
               prtG.DrawString(cTMVAL, MyFont, MyBrush, 110F, nYPos + 165F);
            }
            break;
      }
      cl++;
      if (cl > 5)
      {
         e.HasMorePages = true;
         cl = 0;
         nYPos += 255F;
      }
   }
   e.HasMorePages = false;
   dsPRTDB.Dispose();
}

推荐答案

由于您拥有
,它仅打印一页 最后是e.HasMorePages = false;.

仅在完成打印作业后才将其设置为false.
It prints only one page because you have
e.HasMorePages = false; at the end.

Set it to false only when you''re done with your print job.


无法很好地格式化注释,因此我将在此处回复.

因为for循环总是从0开始,所以它可能打印出相同的内容.如果是这种情况,请将您的"ml"也设置为成员变量.像下面这样的东西应该起作用.

Can''t nicely format comments, so I''ll reply here.

Probably it prints the same thing because the for loop always starts at 0. If that''s the case, make your ''ml'' a member variable as well. Something like the following should work.

private int _cl;
private int _ml;

private void Print_Form(DataSet dsPRTSET)
{
...
...
     _cl = 0;
     _ml = 0;
     prPRVVIEW.Show();
}

private void PF_PRINTPAGE(object sender, PrintPageEventArgs e)
{
...
    while (_ml < dsPRTDB.Tables[0].Rows.Count)
   {
       switch (_cl)
       {
       case 0:
           DrawLine1();
           nYpos += rowHeight;
           DrawLine2();
           nYpose += rowHeight;
           break;
       case 1:
           DrawLine3();
           nYpose += rowHeight;
           break;
...
       }
      _ml++;
   }

    _cl++;
    e.HasMorePages = _cl <= 5;
}



您将不得不在行计数器"_ml"和页面计数器"_cl"之间进行协调.好吧,现在您的"for循环"是错误的,因为它一次通过所有行.您必须通过查看nYpos值来弄清楚如何将其分成几页.

打印并非易事:-)



You''ll have to coordinate between line counter ''_ml'' and what I assume is the page counter ''_cl''. Well, right now your ''for loop'' is wrong because it goes throu all rows in one shot. You''ll have to figure out how to break it into pages by looking at your nYpos value.

Printing is not trivial :-)


这篇关于我需要进行多页打印.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆