Append text to a textbox VB
I am attempting to append information to a textbox in VB. My app allows the user to choose a variety of options and displays all the information in a single, read-only text box.
I would like to set it up so every time an event triggers something to be written in the text box, it gets appended instead of overwriting the text currently in the box.
I have seen some solutions online but a lot of them seemed overly complicated for this task. If anyone has a simple solution, it would开发者_开发百科 be much appreciated.
The only constraint is that text should be appended as a new line, not directly after the last sentence.
Thank you
Private Sub AddLine(ByVal line As String)
Me.txtTheTextbox.Text = If(Me.txtTheTextbox.Text = String.Empty, line, Me.txtTheTextBox.Text & ControlChars.CrLf & line)
End Sub
I know is 8 years late, but in case someone comes here with same question: you can use the TextBox's "AppendText" method.
Dim newText As String = "add this text at the end!"
Me.myTextBox.AppendText(newText)
This way, newText
is appended at the end of myTextBox
, instead of replacing the whole text.
text_read is a read only text box text_live is a normal text box
private sub text_live_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles text_live.TextChanged
text_read.text=text_read.text & text_live.Text ' append the text in live to read
end sub
精彩评论