Help needed re: printing .txt file
-
Hi, I'm really new to coding etc (have only had Visual Basic.Net for about two weeks now). I'm trying to put together a little quiz programme for a friend of mine ( sort of combination of helping him out whilst giving myself something constructive to do to force me to learn the language). Anyways, I've gotten to the point where I can transition between forms, have varied responses based on the questions the students give and have an output whereby I put their score and some other details ( name, dob correct answers to the questions they got wrong etc) into a text file. So far all of that works just fine. My problem is that I want the text file to be printed. It is just a simple file called "script.txt" in the bin folder. Anyways, I have two books which purport to teach one how to learn Visual Basic but NEITHER of them actually gives an example of "How to cause a given text file to be printed when a user presses button x." Could anyone help me out? I'm currently looking at some sort of horrible workaround where I try to get the .txt file to FileStream into a RichTextBox and then print the text content of the RichTextBox but I know there must be some other way. ANY help would be hugely appreciated. I've spent a day banging my head against this particular wall and I'd like to learn the answer for next time.
-
Hi, I'm really new to coding etc (have only had Visual Basic.Net for about two weeks now). I'm trying to put together a little quiz programme for a friend of mine ( sort of combination of helping him out whilst giving myself something constructive to do to force me to learn the language). Anyways, I've gotten to the point where I can transition between forms, have varied responses based on the questions the students give and have an output whereby I put their score and some other details ( name, dob correct answers to the questions they got wrong etc) into a text file. So far all of that works just fine. My problem is that I want the text file to be printed. It is just a simple file called "script.txt" in the bin folder. Anyways, I have two books which purport to teach one how to learn Visual Basic but NEITHER of them actually gives an example of "How to cause a given text file to be printed when a user presses button x." Could anyone help me out? I'm currently looking at some sort of horrible workaround where I try to get the .txt file to FileStream into a RichTextBox and then print the text content of the RichTextBox but I know there must be some other way. ANY help would be hugely appreciated. I've spent a day banging my head against this particular wall and I'd like to learn the answer for next time.
Fionn wrote: I'm currently looking at some sort of horrible workaround where I try to get the .txt file to FileStream into a RichTextBox and then print the text content of the RichTextBox but I know there must be some other way. If it works!?! You could always transfer it to notepad:
notepad /p c:\myfile.txt
But that's a bit horrible because the notepad window opens as it is printing. Then closes down again. --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
-
Fionn wrote: I'm currently looking at some sort of horrible workaround where I try to get the .txt file to FileStream into a RichTextBox and then print the text content of the RichTextBox but I know there must be some other way. If it works!?! You could always transfer it to notepad:
notepad /p c:\myfile.txt
But that's a bit horrible because the notepad window opens as it is printing. Then closes down again. --Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#
Thanks for the help Colin. I played around with it some more and eventually figured that it'd be easier to separate the printing to a file and printing to a printer processes entirely and just wrote the file using PrintLine while Printing the page using the e.Graphics.DrawString approach. It seems to work fairly ok. Still find it amazing that the creators of this could have left out the functionality to just click a button and automatically print a given file. e.Graphics.DrawString(" Insert text here", MyFont, Brushes.Black, X, Y)
-
Thanks for the help Colin. I played around with it some more and eventually figured that it'd be easier to separate the printing to a file and printing to a printer processes entirely and just wrote the file using PrintLine while Printing the page using the e.Graphics.DrawString approach. It seems to work fairly ok. Still find it amazing that the creators of this could have left out the functionality to just click a button and automatically print a given file. e.Graphics.DrawString(" Insert text here", MyFont, Brushes.Black, X, Y)
Fionn wrote: Still find it amazing that the creators of this could have left out the functionality to just click a button and automatically print a given file. That's because printing usually ISN'T done with a straight text file, but with files of many different formats containing all kinds of junk like formatting codes and graphics. RageInTheMachine9532