-
Multiline Label help
Hey guys, I have a problem that I cant seem to figure out. I have a multiline label that im trying to add a line everytime I click the button. Its basically adding a new CD track name, CD minutes, and CD seconds to each new line for everytime the user inputs the given information:
1 Track_Name1 3 min. 13 sec.
2 Track_Name2 2 min. 34 sec.
3 Track_Name3 3 min. 01 sec.
.
.
.
But it keeps adding the "new" line in the position of the old one, so its only displaying on 1 line. I tried using a vbCrLf, but I might have it in the wrong spot?
heres what I got...
Code:
Private Sub btnAddCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddCut.Click
cutCounter += 1
lblPlayList.Text = CStr(cutCounter) & " " & txtTitle.Text & " " & txtCutMin.Text & " min. " & txtCutSec.Text & " sec." & vbCrLf
txtCutMin.Clear()
txtCutSec.Clear()
txtTitle.Clear()
End Sub
The cutCounter is obviously the track number, and it clears the current info for the new information. Thanks for any help...
-
Re: Multiline Label help
This part:
lblPlayList.Text =
means that you will be replacing what is there with the new string. That's not what you want. Replace it with this:
lblPlayList.Text &=
That will take what is there and concatenate on the new part.
-
Re: Multiline Label help
Or if you want to make your code a little easier to understand you could use: -
lblPlayList.Text = lblPlayList.Text + "Whatever"
Of course this will be considered 'Old hat' by some of the purists.
Poppa.
-
Re: Multiline Label help
The only problem I have with that is the use of + rather than &. They do the same thing, and there is technically nothing wrong with that, especially if you have Option Strict ON, but if you don't have Option Strict ON, there are times when + doesn't do what you expect it to do when working with strings that could be interpreted as numbers. Therefore, I much prefer the use of & for string concatenation since there can be no ambiguity about it.
-
Re: Multiline Label help
Is
Code:
lblPlayList.Text = lblPlayList.Text & (whatever) & vbnewline
not sufficient??
-
Re: Multiline Label help
Yes, it is entirely sufficient.