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. printing in vb.net [modified] ... resolved

printing in vb.net [modified] ... resolved

Scheduled Pinned Locked Moved Visual Basic
graphicscsharphelpquestion
6 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.
  • D Offline
    D Offline
    Daniel Engelkes
    wrote on last edited by
    #1

    When I use the following the code to print in prints on one line. How do I put a hard return at the end of each line. So I can have different more than one line.

      Private Sub PrintDocument1_PrintPage_1(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
            For Me.counter = 0 To 19
                e.Graphics.DrawString(writeline(Me.counter), printFont, _
                System.Drawing.Brushes.Black, 10, 10)
            Next Me.counter
        End Sub
    

    by using the follow code resolved the issues

    Dim strPrint As New StringBuilder
            For Me.counter = 0 To 19
                strPrint.Append(printline(Me.counter) & vbCrLf)
            Next Me.counter
    
            e.Graphics.DrawString(strPrint.ToString, printFont, System.Drawing.Brushes.Black, 10, 10)
    
            If System.IO.File.Exists(SaveFileDialog1.FileName) Then
    
                printfile = File.OpenText(SaveFileDialog1.FileName)
                printfile = System.IO.File.OpenText(SaveFileDialog1.FileName)
                Do Until printfile.Peek = -1
                    menuitem(printcounter) = printfile.ReadLine
                    e.Graphics.DrawString(printfile.ReadLine, printFont, _
                    System.Drawing.Brushes.Black, 10, 10)
                    printcounter = printcounter + 1
                Loop
    
                printfile.Close()
    
    
            End If
    

    now the problem is tab spacing.

    modified on Thursday, March 11, 2010 1:40 PM

    W L 2 Replies Last reply
    0
    • D Daniel Engelkes

      When I use the following the code to print in prints on one line. How do I put a hard return at the end of each line. So I can have different more than one line.

        Private Sub PrintDocument1_PrintPage_1(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
              For Me.counter = 0 To 19
                  e.Graphics.DrawString(writeline(Me.counter), printFont, _
                  System.Drawing.Brushes.Black, 10, 10)
              Next Me.counter
          End Sub
      

      by using the follow code resolved the issues

      Dim strPrint As New StringBuilder
              For Me.counter = 0 To 19
                  strPrint.Append(printline(Me.counter) & vbCrLf)
              Next Me.counter
      
              e.Graphics.DrawString(strPrint.ToString, printFont, System.Drawing.Brushes.Black, 10, 10)
      
              If System.IO.File.Exists(SaveFileDialog1.FileName) Then
      
                  printfile = File.OpenText(SaveFileDialog1.FileName)
                  printfile = System.IO.File.OpenText(SaveFileDialog1.FileName)
                  Do Until printfile.Peek = -1
                      menuitem(printcounter) = printfile.ReadLine
                      e.Graphics.DrawString(printfile.ReadLine, printFont, _
                      System.Drawing.Brushes.Black, 10, 10)
                      printcounter = printcounter + 1
                  Loop
      
                  printfile.Close()
      
      
              End If
      

      now the problem is tab spacing.

      modified on Thursday, March 11, 2010 1:40 PM

      W Offline
      W Offline
      Wayne Gaylard
      wrote on last edited by
      #2

      You need to add a line feed char at the end of each line. Try this :

          For Me.counter = 0 To 19
              e.Graphics.DrawString(WriteLine(Me.counter & vbCrLf), printFont, System.Drawing.Brushes.Black, 10, 10)
          Next Me.counter
      

      Hope this helps. [EDIT] Sorry that won't work either. That will print one line on top of another. The best eway to do this is with a stringbuilder like this :

          Dim strPrint As New StringBuilder
          For Me.counter = 0 To 19
              strPrint.Append(counter & vbCrLf)
          Next Me.counter
          e.Graphics.DrawString(strPrint.ToString, New Font("Ariel", 12), System.Drawing.Brushes.Black, 10, 10)
      

      you will need to import System.Text into your class. Hope THIS helps. [/EDIT]

      modified on Wednesday, March 10, 2010 9:12 PM

      D 1 Reply Last reply
      0
      • W Wayne Gaylard

        You need to add a line feed char at the end of each line. Try this :

            For Me.counter = 0 To 19
                e.Graphics.DrawString(WriteLine(Me.counter & vbCrLf), printFont, System.Drawing.Brushes.Black, 10, 10)
            Next Me.counter
        

        Hope this helps. [EDIT] Sorry that won't work either. That will print one line on top of another. The best eway to do this is with a stringbuilder like this :

            Dim strPrint As New StringBuilder
            For Me.counter = 0 To 19
                strPrint.Append(counter & vbCrLf)
            Next Me.counter
            e.Graphics.DrawString(strPrint.ToString, New Font("Ariel", 12), System.Drawing.Brushes.Black, 10, 10)
        

        you will need to import System.Text into your class. Hope THIS helps. [/EDIT]

        modified on Wednesday, March 10, 2010 9:12 PM

        D Offline
        D Offline
        Daniel Engelkes
        wrote on last edited by
        #3

        I have tried hard coding the hard return the string array but still did not work.

        W 1 Reply Last reply
        0
        • D Daniel Engelkes

          I have tried hard coding the hard return the string array but still did not work.

          W Offline
          W Offline
          Wayne Gaylard
          wrote on last edited by
          #4

          Sorry, I don't quite get what you mean, although I tried a test and my second example works perfectly. The only thing was a typo in the font declaration, "Ariel" should be "Arial".

          D 1 Reply Last reply
          0
          • D Daniel Engelkes

            When I use the following the code to print in prints on one line. How do I put a hard return at the end of each line. So I can have different more than one line.

              Private Sub PrintDocument1_PrintPage_1(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
                    For Me.counter = 0 To 19
                        e.Graphics.DrawString(writeline(Me.counter), printFont, _
                        System.Drawing.Brushes.Black, 10, 10)
                    Next Me.counter
                End Sub
            

            by using the follow code resolved the issues

            Dim strPrint As New StringBuilder
                    For Me.counter = 0 To 19
                        strPrint.Append(printline(Me.counter) & vbCrLf)
                    Next Me.counter
            
                    e.Graphics.DrawString(strPrint.ToString, printFont, System.Drawing.Brushes.Black, 10, 10)
            
                    If System.IO.File.Exists(SaveFileDialog1.FileName) Then
            
                        printfile = File.OpenText(SaveFileDialog1.FileName)
                        printfile = System.IO.File.OpenText(SaveFileDialog1.FileName)
                        Do Until printfile.Peek = -1
                            menuitem(printcounter) = printfile.ReadLine
                            e.Graphics.DrawString(printfile.ReadLine, printFont, _
                            System.Drawing.Brushes.Black, 10, 10)
                            printcounter = printcounter + 1
                        Loop
            
                        printfile.Close()
            
            
                    End If
            

            now the problem is tab spacing.

            modified on Thursday, March 11, 2010 1:40 PM

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            You can Check it to Paste it Code to Print Preview Control.

            If you can think then I Can.

            1 Reply Last reply
            0
            • W Wayne Gaylard

              Sorry, I don't quite get what you mean, although I tried a test and my second example works perfectly. The only thing was a typo in the font declaration, "Ariel" should be "Arial".

              D Offline
              D Offline
              Daniel Engelkes
              wrote on last edited by
              #6

              why are we appending the counter which is an index of the wriline string array.

               Dim strPrint As New StringBuilder
                      For Me.counter = 0 To 19
                          strPrint.Append(counter & vbCrLf)
                      Next Me.counter
                      e.Graphics.DrawString(strPrint.ToString, New Font("Ariel", 12), System.Drawing.Brushes.Black, 10, 10)
              

              should be <pre><code> Dim strPrint As New StringBuilder For Me.counter = 0 To 19 strPrint.Append(writeline(me.counter) & vbCrLf) Next Me.counter e.Graphics.DrawString(strPrint.ToString, New Font("Ariel", 12), System.Drawing.Brushes.Black, 10, 10)</code></pre>

              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