当前位置:编程学习 > C#/ASP.NET >>

C# printPreviewDialog 打印预览只显示一页

各位高手指点下  1、我在用PrintDocument实现 数据打印的时候,printPreviewDialog打印预览  只显示一页,实际数据可以显示好几页。

2、现在打印的数据,图片上显示了三组的数据,怎么实现每一页只显示一组数据。
可能是我下面的方面写的有点问题,我在一个循环里把内容都添加到一个e.Graphics上了,因为之前没有接触这类打印,希望高手 教教小弟,多谢!!!



 private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Font headFont = new System.Drawing.Font("宋体", 20);
            Font headFont_ = new System.Drawing.Font("宋体", 18);
            Font ksFont = new System.Drawing.Font("宋体", 16);
            Font FontData = new System.Drawing.Font("宋体", 14);
            Brush myBrush = Brushes.Black;
            int ofleft = 15;
            int lineIndex =0;
            foreach (string id in list_ID)
            {
               DataTable dt_items = GetItems(id);  //获取每个单号对应的药品数据
               if (dt_items.Rows.Count > 0)
               {
                   
                   string ks = dt_items.Rows[0]["科室名称"].ToString();
                   string djid = dt_items.Rows[0]["单据编号"].ToString();
                   string cztime = dt_items.Rows[0]["操作时间"].ToString();

                   e.Graphics.DrawString("第三附属医院", headFont, myBrush, 450, 20+lineIndex*30);
                   lineIndex++;
                   e.Graphics.DrawString("摆药工作单(药品汇总) 存取柜", headFont_, myBrush, 430, 20 + lineIndex * 30);
                   lineIndex++;
                   e.Graphics.DrawString("科室:", ksFont, myBrush, ofleft, 20 + lineIndex * 30);
                   e.Graphics.DrawString(ks, ksFont, myBrush, 75, 20 + lineIndex * 30);   //科室名称
                   e.Graphics.DrawString("单据编号:", ksFont, myBrush, 400, 20 + lineIndex * 30);
                   e.Graphics.DrawString(djid, ksFont, myBrush, 510, 20 + lineIndex * 30);  //单据号
                   lineIndex++;
                   //更具画布的宽度,话虚线
                   int pagewidth = e.MarginBounds.Width;
                   for (int i = ofleft; i < pagewidth - ofleft; )
                   {
                       e.Graphics.DrawString(".", FontData, myBrush, i, 20 + lineIndex * 30);
                       i = i + 4;
                   }
                   lineIndex++;
                   e.Graphics.DrawString("药品名称", ksFont, myBrush, ofleft + 40, 20 + lineIndex * 30);   //药品名称
                   e.Graphics.DrawString("规格", ksFont, myBrush, ofleft + 300, 20 + lineIndex * 30);
                   e.Graphics.DrawString("数量", ksFont, myBrush, ofleft + 430, 20 + lineIndex * 30);
                   e.Graphics.DrawString("单位", ksFont, myBrush, ofleft + 500, 20 + lineIndex * 30);
                   e.Graphics.DrawString("厂家", ksFont, myBrush, ofleft + 600, 20 + lineIndex * 30);
                   e.Graphics.DrawString("单价", ksFont, myBrush, ofleft + 700, 20 + lineIndex * 30);
                   e.Graphics.DrawString("金额", ksFont, myBrush, ofleft + 800, 20 + lineIndex * 30);
                   e.Graphics.DrawString("货架", ksFont, myBrush, ofleft + 900, 20 + lineIndex * 30);
                   lineIndex++;
                   for (int i = ofleft; i < pagewidth - ofleft; )
                   {
                       e.Graphics.DrawString(".", FontData, myBrush, i, 20 + lineIndex * 30);
                       i = i + 4;
                   }

                   //循环得到的药品信息  添加到画布中......
                   for (int j = 0; j < dt_items.Rows.Count; j++)
                   {
                       lineIndex++;
                       e.Graphics.DrawString(dt_items.Rows[j]["药品名称"].ToString(), ksFont, myBrush, ofleft, 20 + lineIndex * 30);   //药品名称
                       e.Graphics.DrawString(dt_items.Rows[j]["药品规格"].ToString(), ksFont, myBrush, ofleft + 300, 20 + lineIndex * 30);
                       e.Graphics.DrawString(dt_items.Rows[j]["出药数量"].ToString(), ksFont, myBrush, ofleft + 430, 20 + lineIndex * 30);
                       e.Graphics.DrawString(dt_items.Rows[j]["药品包装"].ToString(), ksFont, myBrush, ofleft + 500, 20 + lineIndex * 30);
                       e.Graphics.DrawString(dt_items.Rows[j]["生产商家"].ToString(), ksFont, myBrush, ofleft + 600, 20 + lineIndex * 30);
                       e.Graphics.DrawString(double.Parse( dt_items.Rows[j]["药品单价"].ToString()).ToString("F2"), ksFont, myBrush, ofleft + 700, 20 + lineIndex * 30);
                       e.Graphics.DrawString(double.Parse( dt_items.Rows[j]["价格小计"].ToString()).ToString("F2"), ksFont, myBrush, ofleft + 800, 20 + lineIndex * 30);
                       e.Graphics.DrawString(dt_items.Rows[j]["药架号"].ToString(), ksFont, myBrush, ofleft + 900, 20 + lineIndex * 30);
                   }
                   lineIndex++;
                   for (int i = ofleft; i < pagewidth - ofleft; )
                   {
                       e.Graphics.DrawString(".", FontData, myBrush, i, 20 + lineIndex * 30);
                       i = i + 4;
                   }
                   lineIndex++;
                   e.Graphics.DrawString("核对人:", ksFont, myBrush, ofleft , 20 + lineIndex * 30);   
                   e.Graphics.DrawString("护士核对人:", ksFont, myBrush, ofleft + 200, 20 + lineIndex * 30);
                   e.Graphics.DrawString("摆药时间:", ksFont, myBrush, ofleft + 400, 20 + lineIndex * 30);
                   e.Graphics.DrawString(cztime, ksFont, myBrush, ofleft + 520, 20 + lineIndex * 30);
                   lineIndex++;

                   UpdataInfo(id);      //打印后修改数据
               }
               e.HasMorePages = false;   //改成true 之后,预览的时候一直在生成新的预览页面,但是生成预览界面都是空白的。
            }               
            
        }



private void PrintPreview()   //预览的方法
        {
            printPreviewDialog1.Document = printDocument1;
            printPreviewDialog1.ShowDialog();
        }
C# Print打印 --------------------编程问答-------------------- 等待高人.... --------------------编程问答-------------------- 图片右上角 页(P ) 你点一下上翻的,看能不能增加,如果能表示有多页。 --------------------编程问答-------------------- 除
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,