Columns in a string in VB.NET
-
Hello everybody. I am trying to create a string which will have spaces in between words that create "columns". In vb6 i used to use tab(). EG string 3 = string1 & tab(5) & string2 and i would have the following: areaName PostCode Suburb test 125 the suburb test2 225 another suburb so when i use the print command to have it in columns. How to i do that in vb.net. Thank you in advance. Still trying to find the way
-
Hello everybody. I am trying to create a string which will have spaces in between words that create "columns". In vb6 i used to use tab(). EG string 3 = string1 & tab(5) & string2 and i would have the following: areaName PostCode Suburb test 125 the suburb test2 225 another suburb so when i use the print command to have it in columns. How to i do that in vb.net. Thank you in advance. Still trying to find the way
I just had that same problem. Here is an example:
' Draw all font names on form Dim gr As Graphics = Me.CreateGraphics gr.Clear(Color.White) ' Prepare a message with tabs and carriage returns. Dim msg As String = String.Format("{0}Column 1{0}Column 2{0}Column 3{1}" _ & "Row 1{0}Cell (1,1){0}Cell (1,2){0}Cell (1,3){1}" _ & "Row 2{0}Cell (2,1){0}Cell (2,2){0}Cell (2,3){1}", _ ControlChars.Tab, ControlChars.CrLf) Dim fnt As New Font("Arial", 12) Dim strFormat As New StringFormat() ' Set the tab stops. Dim tabStops() As Single = {80, 140, 200} strFormat.SetTabStops(0, tabStops) ' Draw the text with specified tab stops. gr.DrawString(msg, fnt, Brushes.Black, 20, 20, strFormat) fnt.Dispose() gr.Dispose()
Hope that hels you!