I have written software that creates a text file, the text file contains colums of data. When I view and print the text file using notepad all the colums line up correctly. I am now trying to print the text file using a button on my form but every time I print it all the colums are no longer lined up :-(

This is the code that I'm using to do the print.

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
       
        Dim LinesPerPage As Single = 0
        Dim yPosition As Single = 0
        Dim count As Integer = 0
        Dim leftMargin As Single = e.MarginBounds.Left
        Dim topMargin As Single = e.MarginBounds.Top
        Dim strLine As String = Nothing
        Dim printFont As Font = Me.lblFadeRate.Font
        Dim myBrush As New SolidBrush(Color.Black)

        'Work out the number of lines per page, using the MarginBounds.
        LinesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)

        'Iterate over the string using the StringBuilder, printing each line.
        strLine = MyStreamReader.ReadLine
        While count < LinesPerPage
            'Calculate the next line position based on the height on the font according
            'to the printing device
            yPosition = (topMargin + (count * printFont.GetHeight(e.Graphics)))

            'draw the next line in the stream
            e.Graphics.DrawString(strLine, printFont, myBrush, leftMargin, yPosition, New StringFormat())
            count += 1
            strLine = MyStreamReader.ReadLine
        End While

        'check to see if there is another page left to print
        If MyStreamReader.EndOfStream = False Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
            MyStreamReader.Close()  'Close stream reader
        End If
    End Sub

Am I missing a setting somewhere???


Thanks for any help you can give me

Simon

Are you printing from the same system on which your code resides.

Are you printing from the same system on which your code resides.

Are yo sure the printer is not a network printer and the font of notepad is same every where.

Hi Simon,

make the Font of the NotePad "Courier New", it is a UniDistant font (all fonts acquire same space on screen/media), ur texts will look like Columns..

REgards
Veena

Hi Simon,

make the Font of the NotePad "Courier New", it is a UniDistant font (all fonts acquire same space on screen/media), ur texts will look like Columns..

REgards
Veena

Thanks for that :) It worked a treat

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.