Question How can I format the text output to a textbox so it adheres to a predefined width?

chevron

Member
Joined
Sep 21, 2010
Messages
8
Location
India
Programming Experience
Beginner
Hello, I found a code snippet online:

VB.NET:
Imports System.IO
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = String.Empty
        Using fs As New FileStream("c:\test.txt", FileMode.Open)
            fs.Position = 10
            Using br As New BinaryReader(fs)
                For x As Int16 = 0 To 100
                    TextBox1.Text &= Asc(br.ReadChar) & " "
                Next
            End Using
        End Using
    End Sub
End Class

But the problem is that the text it outputs isn't properly formatted. It must adhere to a predefined width. Something like the setw() function in C/C++.

Please help!
Thanks!
 
Re:

Thanks JohnH!

That was really helpful, but it solved another problem I was facing.
I actually wanted to know how to format the data retrieved so that instead of looking like this:

VB.NET:
1. Some text
2. Some more text
...
9. Even more text
10. Beyond text

it looked something like this:
VB.NET:
1.   Some text
2.   Some more text
...
9.   Even more text
10.  Beyond text
...
100. Lorem ipsum

Thanks :)
 
Back
Top