How do I print to a printer from a console application?
-
samedi 23 avril 2011 21:14
I was walking through the System.Printing namespace using a console application trying to learn to print data from an object to a printer. It seems pretty simple to navigate the printers on my system as well as on my network. But I can't find a damn "print" command. How do I send actual data to a printer?
I finally figured out how to send a string using the system.drawing.printing namespace. But I can't figure out how to tell it which printer to send to, programmatically.
If you can answer both of these questions, it would help a lot. Thanks :)
Toutes les réponses
-
samedi 23 avril 2011 22:14If you want a Print command, use System.Drawing.Printing.PrintDocument. Ask your question on the appropriate forum: Windows Forms for System.Drawing.Printing or WindowsPresentationFoundation for System.Printing.
-
samedi 23 avril 2011 22:28
I am asking it on the right forum. I'm using c#. I want to print from a console application. I am using express edition.
If you want to post an answer make sure you read my question first. That way you save my time and yours.
-
samedi 23 avril 2011 22:37
I am asking it on the right forum. I'm using c#. I want to print from a console application. I am using express edition.
If you want to post an answer make sure you read my question first. That way you save my time and yours.
C# has no built-in printing capability. You are not asking your question on a forum that has anything to do with printing. -
mardi 26 avril 2011 03:30
Hi Crushbrain,
Based on your description, do you mean that you want to call a printer to print something in a console application?
If so, I think you can check these similar cases here:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/9495a597-7e9d-4653-8740-ea61540dc850/
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/2a77f7d4-9827-4296-b13a-268a80ddce5a/There are two ways to achieve that:
- Use P/Invoke to to that. Please refer to the first link.
- Add the proper dlls(System.Drawing.Printing, System.Windows.Forms). Check the second link.
Hope it helps solve your problem. Thanks.
Vin Jin [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

- Marqué comme réponse crushbrain mercredi 27 avril 2011 17:58
-
vendredi 3 août 2012 15:17I hate it when people ask legitimate questions about a legitimate problem in a proper format and CERTAINLY in the appropriate FORUM. I am tired of people on their high horses telling inquiring minds, in no uncertain words, to 'get lost' and ask your question somewhere else.

