Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Help needed re: printing .txt file

Help needed re: printing .txt file

Scheduled Pinned Locked Moved Visual Basic
helptutorialcsharptools
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fionn
    wrote on last edited by
    #1

    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.

    C 1 Reply Last reply
    0
    • F Fionn

      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.

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      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#

      F 1 Reply Last reply
      0
      • C Colin Angus Mackay

        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#

        F Offline
        F Offline
        Fionn
        wrote on last edited by
        #3

        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)

        D 1 Reply Last reply
        0
        • F Fionn

          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)

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups