Results 1 to 3 of 3

Thread: Help in aligning printing

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    145

    Help in aligning printing

    Hi all,

    I am using streamwriter to write to a text file result from my select statement. I am also using printdialog and printdocument control to print the text file directly to the printer.

    However, when the output is printed, the columns are not aligned. But when I viewed the text file, the columns are aligned correctly.

    I don't know what made them un-aligned. Below is my code to print to printer.

    Code:
    Sub printdata()
            Try
                StreamToPrint = New IO.StreamReader("consultreport.txt")
                PrintDialog1.Document = PrintDocument1
                PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
                PrintDialog1.AllowSomePages = True
                If PrintDialog1.ShowDialog = DialogResult.OK Then
                    PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
                    PrintDocument1.Print()
                    If Not (StreamToPrint Is Nothing) Then
                        StreamToPrint.Close()
                    End If
                End If
            Catch ex As ArithmeticException
                MessageBox.Show(ex.Message & ex.StackTrace)
            End Try
        End Sub
    
        Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
            Dim PrintFont As New Font("Gill Sans", 9)
            Dim LinesPerPage As Single = e.MarginBounds.Height / PrintFont.GetHeight(e.Graphics)
            Dim Line As String = Nothing, count As Integer, yPos As Single = 0
    
            For count = 0 To LinesPerPage - 1
                Line = StreamToPrint.ReadLine
                If Line Is Nothing Then Exit For
                yPos = e.MarginBounds.Top + count * PrintFont.GetHeight(e.Graphics)
                e.Graphics.DrawString(Line, PrintFont, Brushes.Black, e.MarginBounds.Left, yPos, New StringFormat())
            Next
            If Not (Line Is Nothing) Then e.HasMorePages = True
        End Sub
    Many Thanks.

  2. #2
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Just a thought, but have you tried it on more than one printer? I have had problems with certain versions of printer drivers previously. Just a thought...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    145
    Yes, I've already run the system to use 3 different printers. 2 laser jets and 1 desk jet. But the output is the same on the 3 printers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width