Arrange the Text File Alignment (Picture)

knockyo

Well-known member
Joined
Sep 20, 2006
Messages
78
Programming Experience
1-3
Here is the text file alignment result that i generate out using below coding
arrtext1to0.jpg


Here is my coding

VB.NET:
 '=== PARAMETER Report ===
        '------------------------------------------------------------
        Dim param As String = vbNewLine & "PARAMETER " & vbNewLine
        Dim dtparam As New DataTable
        dtparam = CType(dgParam.DataSource, DataTable)

        For m As Integer = 0 To dtparam.Columns.Count - 1
            param = param & dgParam.DisplayLayout.Bands(0).Columns(m).Header.Caption & "     "
        Next
        param = param & vbNewLine

        For i As Integer = 0 To dtparam.Rows.Count - 1
            For j As Integer = 0 To dtparam.Columns.Count - 1
                param = param & dtparam.Rows(i)(j).ToString & "     "
            Next
            param = param & vbNewLine
        Next
        '------------------------------------------------------------


        '=== REJECT PROFILE ANALYSIS Report  ===
        '------------------------------------------------------------
        Dim RPA As String = vbNewLine & "REJECT PROFILE ANALYSIS " & vbNewLine
        Dim dtRPA As New DataTable
        dtRPA = CType(dgRPA.DataSource, DataTable)

        For m As Integer = 0 To dtRPA.Columns.Count - 2
            RPA = RPA & dgRPA.DisplayLayout.Bands(0).Columns(m).Header.Caption & "     "
        Next
        RPA = RPA & vbNewLine

        For i As Integer = 0 To dtRPA.Rows.Count - 1
            For j As Integer = 0 To dtRPA.Columns.Count - 2
                RPA = RPA & dtRPA.Rows(i)(j).ToString & "     "
            Next
            RPA = RPA & vbNewLine
        Next
        '------------------------------------------------------------
How i can show the result alignment with exactly fit into like table? Eg:
arrtext2uc7.jpg
 
Last edited:
First you have to use a font that display equal width for each character, like Courier New and Lucida Console fonts. Second you should use the System.Text.StringBuilder when you are building large text, not a String variable. Look into the StringBuilder method AppendFormat that will allow you to specify space-padded "columns".
 
Thx ur idea, i get the solution. After that I need PRINT PREVIEW and print the data.

During my PRINT PREVIEW, i can show out all the information, but when i press print, it did not print any data. Below is my code:

VB.NET:
Try
            streamToPrint = New StreamReader("C:\sample.txt")
            Dim ppd As New PrintPreviewDialog
            Try
                printFont = New Font("Lucida Console", 10)
                Dim pd As New PrintDocument
                AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
                ppd.Document = pd
                ppd.ShowDialog()
            Finally
                streamToPrint.Close()
                'delete printing.txt 
            End Try
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

thx again
 
Everything you see in the preview window with that code is also printed if you click the 'print' button in dialog, so I don't exactly understand what you mean.
 
actually i can preview at the Preview screen

after that i try to press print icon at print preview, it cannot print out, just a blank page!

can u show me show printing example that retrieve data from text file (c:\test.txt) and print it?
 
If your pd_PrintPage method contains this code below it will preview "string" and when you click 'print' button it will print the same to printer:
VB.NET:
Dim printFont As New Font("Lucida Console", 10)
e.Graphics.DrawString("string", printFont, Brushes.Black, 10, 10)
 
but when i print with my printer, it contain empty page, no data will print out!'

do you have any idea how to grab text file data and print it out?
 
That is not what I'm seeing, I see the word "string" in upper left corner both in preview and in print-out.
 
See also the second post of this thread, there is linked to a ready-made class that you can use to print long text and it will dynamically print to several pages if necessary, you can also specify the font when using that class. The class inherits PrintDocument so you can also assign it directly to the PrintPreviewDialog.Document after it is configured with the text and font.
 
Back
Top