如何找到打印的页数? [英] How can I find how many pages printed ?

查看:90
本文介绍了如何找到打印的页数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

我需要一个代码来检查打印机纸张。

例如我打印一个文本文件它将会是3页(s),现在怎么样?我在Windows应用程序中输入了这个3页?

tnx all。

解决方案

你需要能够检查低水平的打印机/队列等



这里有一些可能帮助你入门的链接



http://support.microsoft.com/kb/202480 [ ^ ]



http://support.microsoft.com/kb/228769/EN-US [ ^ ]



他们可能不在vb.net抱歉,但向您展示了您可能需要做的事情


因为这是 System.Windows.Forms 应用程序,通常你需要使用类 System.Drawing.Printing.PrintDocument http://msdn.microsoft.com/en-us/library/system.drawing.printing。 printdocument.aspx [ ^ ]。



现在,看看最后的小代码示例。它应该如何打印,特别是如何通过向事件的调用列表添加处理程序来打印页面 System.Drawing.Printing.PrintDocument.PrintPage ,请参阅 http://msdn.microsoft.com/en-us/library /system.drawing.printing.printdocument.printpage.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs.aspx [ ^ ]。



在处理程序的实现中添加一些计数器;并且你已经完成了:

  void  PrintADocument(SomeData someData  / *   ... * / ){
// ...
PrintDocument pd = new PrintDocument();
uint pageCount = 0 ;
pd.PrintPage + =(sender,eventArgs){ // 以lambda形式,参数的确切类型可以
// 从事件类型推断
系统.Drawing.Graphics graphics = eventArgs.Graphics; // 参见上面的链接
RenderThePageUsingTheInstanceOfGraphics(graphics,someData);
// 您要在此页面上呈现的内容
pageCount ++;
}; // pd.PrintPage handle
pd.Print();
// 此刻,您知道打印了多少页,请阅读pageCount
// ...
} // PrintADocument





在这段代码中,我也是使用了一个有趣的功能,与匿名方法相关,以及使用堆栈变量 pageCount ,称为 closure 。这很有趣,可以学习。

http://en.wikipedia.org/wiki / Closure_%28computer_science%29 [ ^ ],

http://en.wikipedia.org/wiki/Anonymous_method [< a href =http://en.wikipedia.org/wiki/Anonymous_methodtarget =_ blanktitle =New Window> ^ ],

http://en.wikipedia.org/wiki/Anonymous_method#C.23_lambda_expressions [ ^ ]。



< DD> -SA


Hi .
I need a code to check the printer papers out.
for example i print a text document it will 3 page(s), now how can i fount this "3 page(s)" in a windows application?
tnx all.

解决方案

You need to be able to inspect printers/queues etc at a low level

Here''s some link''s that "may" help you get started

http://support.microsoft.com/kb/202480[^]

http://support.microsoft.com/kb/228769/EN-US[^]

They may not be in vb.net sorry, but show you the sorts of things you may have to do


As this is a System.Windows.Forms application, normally you need to use the class System.Drawing.Printing.PrintDocument: http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^].

Now, look at the small code sample at the end. It should how to print, and, in particular, how to print a page by adding a handler to the invocation list of the event System.Drawing.Printing.PrintDocument.PrintPage, see http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.printpage.aspx[^],
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs.aspx[^].

Add some counter in the implementation of the handler; and you are done:

void PrintADocument(SomeData someData /* ... */) {
   // ...
   PrintDocument pd = new PrintDocument();
   uint pageCount = 0;
   pd.PrintPage += (sender, eventArgs) { // in lambda form, exact types of the parameters can be
                                         // inferred from the event type
      System.Drawing.Graphics graphics  = eventArgs.Graphics; // see the link above
      RenderThePageUsingTheInstanceOfGraphics(graphics, someData);
            // whatever you want to render on this page
      pageCount++;
   }; // pd.PrintPage handle
   pd.Print();
   // at this moment, you know how many pages are printed, read pageCount 
   // ...
} //PrintADocument



In this code, I also used an interesting feature, related to anonymous methods and the use of the stack variable pageCount, called closure. This is interesting enough to learn.
http://en.wikipedia.org/wiki/Closure_%28computer_science%29[^],
http://en.wikipedia.org/wiki/Anonymous_method[^],
http://en.wikipedia.org/wiki/Anonymous_method#C.23_lambda_expressions[^].

—SA


这篇关于如何找到打印的页数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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