add txt to a new line in a label
Hello, I am trying to display log information to the user from the database. It works fine my only problem is that I cannot find a way to control how it looks. I have the log data output to one sting that I put together in a loop. I am only using one label to display it all (about 8 – 15 entries). Is there a way to put a new line into a label filed so I can append the data to a new line? If that makes any sense.
Thanks
Re: add txt to a new line in a label
Try using a textbox with multiline set to true instead of a label, and as you add a new line to the text insert a line feed 'vbcrlf'
Re: add txt to a new line in a label
No, don't do that. vbCrLf is outmoded.
You can use a stringbuilder with the AppendLine() function, then send that back to the label like this:
VB Code:
Dim myStringBuilder As New System.Text.StringBuilder
myStringBuilder.AppendLine(string goes here)
Label1.Text = myStringBuilder.ToString()
Re: add txt to a new line in a label
Thank you both for your help. I would perfer to use the second method but it soesnt seem to put the data onto a new line it still shows up like this:
Code to make string
Dim result As New System.Text.StringBuilder
While DataReader.Read()
Result.AppendLine(DataReader("test_data"))
End While
Label.Text = result
Results look like this:
'Successfully Renamed and moved 00007665.jpg to 5-05-072-11 09-Sep-2005.jpg' 'Successfully Renamed and moved 00007665.jpg to 5-05-072-11 09-Sep-2005.jpg' 'Successfully Renamed and moved 03vvt2kt.tif to PLA1900.tif' 'Successfully Renamed and moved 03vvt2kt.tif to PLA1900.tif' 'Successfully Renamed and moved 1xpbazcg.tif to EZE860013.tif' 'Successfully Renamed and moved 1xpbazcg.tif to EZE860013.tif' 'Successfully Renamed and moved 2xvuaibv.tif to MSL3078.ti
there should be a new line at each "'Successfully "
Thanks again
Re: add txt to a new line in a label
Yes, there should be a new line. My test worked, for me
Make sure the label isn't autosizing.
also, change it to Label.Text = Result.ToString()
Re: add txt to a new line in a label
Actually you can do it with simple string concatenation as well, as long as you aren't working with extremely large strings... and I would use Environment.Newline instead of vbcrlf...
VB Code:
Label1.Text = "This is the first line" & Environment.NewLine & "This is the second line"
Re: add txt to a new line in a label
Great... works great thanks for the help