How can i print a text file in c#?
I've been looking on the internet and found code, but I just need it on paper, don't care what type of letters, just a regular print..
And i want to keep the code short.
I've found long code, but I've got to make it work at thuesday 25/05..
I tried:
PrintDocument pd = new PrintDocument();
pd.DocumentName = ("c:\\GIP_Foto\\data.log");
But it just opens a new screen to select what you want to print..
need help?

8 Years
Discussion Span
Last Post by Isaaac

that's the one I found to, but it's pretty long..
+ I only understand half of his code


when i already know where the file is, how do i replace the first button?
I know the printing part, but I don't understand a lot of the PrintTextFileHandler..

But replacing the path should give me:

//Create a StreamReader object
reader = new StreamReader (c:\\gip_foto\\data.log);
//Create a Verdana font with size 10
verdana10Font = new Font ("Verdana", 10);
//Create a PrintDocument object
PrintDocument pd = new PrintDocument();
//Add PrintPage event handler
pd.PrintPage += new PrintPageEventHandler(this.PrintTextFileHandler);
//Call Print Method
//Close the reader
if (reader != null)

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).


Problem solved, I copied code, but when I cancel the print (after clicking print), there's a fault, but i just catch it with an exception message..
Thanks anyway!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.