VB.Net question with formatting Text

phantom404

Golden Member
Nov 2, 2004
1,460
2
81
I have a database with information and I want to display them in a form and on the form have a print button to print out the page.

Everything is done except I cant figure out how to get the text to line up in columns.

Ex.(how it looks now)
--------------------------------
| Michael 12344 |
| Rosie 456778 |
| Tony 54345 |
-------------------------------

I need it to look like this where no matter how long the name is the next column will start at a certain posistion
 

hellman69

Member
Feb 15, 2003
180
0
71
Use the PadRight class of String. So str.PadRight(20, " ") will put 20 empty spaces after the name. You'll need a set length, say 50. For the name then you would output str.Trim().PadRight(50-str.Length, " ")

Trevor
 

phantom404

Golden Member
Nov 2, 2004
1,460
2
81
Sweet thanks alot had to modify it alittle because of .net 2005

LLength = LName.Length
LName = LName.PadRight(20 - LLength)

One problem im running into now is that the size of each letter is different its throwing off the line up of the columns....is there any way to take care of that.
 

phantom404

Golden Member
Nov 2, 2004
1,460
2
81
Sweet, I figured it out. I mis read what PadRigth(x) did. I thought it started at the end of the string and counted for X amount of spaces to the right resulting in 20 all together using a first name with 7 characters. It turns out it starts from the begining of the string and coutns.