确保打印机打印最后一行 [英] Make sure printer prints last line

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

问题描述

System.Drawing.Printing.PrintDocument p = new System.Drawing.Printing.PrintDocument();
                 p.PrinterSettings.PrinterName = cbInstalledPrinter.Text;

                 char splitter = '\n';
                 char splitter2 = '\r';

                 string[] test1 = txtTextToPrint.Text.Split(splitter);

                 foreach (string s in test1)
                 {
                     Console.WriteLine(s);
                 }

                 p.PrintPage += delegate(object sender1, System.Drawing.Printing.PrintPageEventArgs e1)
                 {
                     float x = 10;
                     float y = 5;
                     float height = 0F;

                      Font drawFont = new Font("Times New Roman", 8, FontStyle.Regular);

                     string[] test = txtTextToPrint.Text.Split(splitter);

                     foreach (string s in test)
                     {
                         string text = s.Trim();
                         e1.Graphics.DrawString(text, drawFont, new SolidBrush(Color.Black), new RectangleF(x, y,
                         p.DefaultPageSettings.PrintableArea.Width, height));
                         y += e1.Graphics.MeasureString(text, drawFont).Height;
                         e1.Graphics.Flush();
                     }
                 };

                 p.Print();





这是我用来打印的。但由于一些奇怪的原因,它只打印到第二行,然后当我再次打印时,它首先打印最后一行,然后开始打印作业,直到第二行...然后继续。打印机连接到LPT2,需要在此端口上工作。如果它连接到任何其他端口它完美地工作......但我们需要使用LPT2。



我尝试过:



刷新缓冲区......

更改fontStyle

拆分行

作为一个格式化字符串发送到打印机。



This is what I use to print. But for some odd reason it only prints till the second last line, then when I print again, it first prints the last line and then starts the printing job till the second last line...and so it continues. The printer is connected to LPT2 and needs to work on this port. If it connects to any other port it works perfectly...but we need to use LPT2.

What I have tried:

Flushing the buffer...
Changing the fontStyle
Splitting the lines
Sending to the printer as one formatted string.

推荐答案

在实际打印后发送几个空行。
Send a couple of blank lines after the actual print.


这篇关于确保打印机打印最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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