Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET windows.forms
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.
Posted 2-Dec-12 11:32am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
Rad.Application at 3-Dec-12 11:29am
   
my application does not print anything . print statement come from other programs . i need to enumeration the paper printed :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v2
Comments
Rad.Application at 3-Dec-12 11:28am
   
my application does not print anything . print statement come from other programs . i need to enumeration the paper printed
:)
Sergey Alexandrovich Kryukov at 3-Dec-12 12:40pm
   
Then the other program should do it; or, why not printing from your code? Isn't it logical? Whoever is printing, counts the pages. If you need something else, you need to share information on your design, and -- importantly -- motivate it, explain your ultimate goals. How about this route?
--SA
Garth J Lancaster at 3-Dec-12 18:29pm
   
you can still monitor print jobs/queues etc they are global to your machine - but as Sergey said, ideally whoever is doing printing should count the pages - and yes, you havnt given us enough real information
Rad.Application at 3-Dec-12 21:22pm
   
I wrote a coffee net manager last year . My customer has a shared printer on his network, now he want to know each client how many paper printed .
i have no idea , my English is not good too. my bad , sorry for this.
Sergey Alexandrovich Kryukov at 3-Dec-12 21:53pm
   
Listen to a good advise, do it in civilized way...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,649
1 Sergey Alexandrovich Kryukov 6,270
2 CPallini 5,190
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 2 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100