简体   繁体   English

Append 文本到文本框 VB

[英]Append text to a textbox VB

I am attempting to append information to a textbox in VB.我正在尝试将 append 信息写入 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.我知道已经晚了 8 年,但如果有人带着同样的问题来到这里:你可以使用 TextBox 的“AppendText”方法。

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.这样, newText附加myTextBox的末尾,而不是替换整个文本。

text_read is a read only text box text_live is a normal text box text_read 是只读文本框 text_live 是普通文本框

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM