如何在不替换第一个输入的情况下在文本框中添加新显示
How to add new display in textbox without replacing the first input
您好,我正在创建一个类似聊天的应用程序。你能帮帮我吗?
当我输入新消息时,初始显示的消息被替换:(
请看下面我的代码:
Private Sub saveMessage()
FileName = Format(Now, "MMddyyyyhhmmss")
Dim RecipientFile As String
If CurrentRecipient = "Edward" Then
RecipientFile = RecipientFolder & FileName & ".txt"
ElseIf CurrentRecipient = "Criziel" Then
RecipientFile = RecipientFolder & FileName & ".txt"
ElseIf CurrentRecipient = "Jerome" Then
RecipientFile = RecipientFile & FileName & ".txt"
Else
Exit Sub
End If
Dim Writer As IO.StreamWriter
Writer = New IO.StreamWriter(RecipientFile)
Writer.Write(MainRichTextBox.Text)
Writer.Close()
ShowtextRichTextBox.Text = (User & " : ") & MainRichTextBox.Text
MainRichTextBox.Clear()
End Sub
提前致谢! :*
您的以下代码只是将最新值分配(替换)到富文本框,
ShowtextRichTextBox.Text = (User & " : ") & MainRichTextBox.Text
相反,您应该附加如下文本,
ShowtextRichTextBox.Text &= (User & " : ") & MainRichTextBox.Text
此外,您可以尝试使用 RichTextBox 的内置方法来附加文本,例如 ShowtextRichTextBox.AppendText((User & " : ") & MainRichTextBox.Text)
注意:追加时,还应在新文本前添加换行符,如ShowtextRichTextBox.Text &= Environment.NewLine & (User & " : ") & MainRichTextBox.Text
.
修改后的代码,
Private Sub saveMessage()
FileName = Format(Now, "MMddyyyyhhmmss")
Dim RecipientFile As String
If CurrentRecipient = "Edward" Then
RecipientFile = RecipientFolder & FileName & ".txt"
ElseIf CurrentRecipient = "Criziel" Then
RecipientFile = RecipientFolder & FileName & ".txt"
ElseIf CurrentRecipient = "Jerome" Then
RecipientFile = RecipientFile & FileName & ".txt"
Else
Exit Sub
End If
Dim Writer As IO.StreamWriter
Writer = New IO.StreamWriter(RecipientFile)
Writer.Write(MainRichTextBox.Text)
Writer.Close()
ShowtextRichTextBox.Text &= Environment.NewLine & (User & " : ") & MainRichTextBox.Text
MainRichTextBox.Clear()
End Sub
您好,我正在创建一个类似聊天的应用程序。你能帮帮我吗? 当我输入新消息时,初始显示的消息被替换:(
请看下面我的代码:
Private Sub saveMessage()
FileName = Format(Now, "MMddyyyyhhmmss")
Dim RecipientFile As String
If CurrentRecipient = "Edward" Then
RecipientFile = RecipientFolder & FileName & ".txt"
ElseIf CurrentRecipient = "Criziel" Then
RecipientFile = RecipientFolder & FileName & ".txt"
ElseIf CurrentRecipient = "Jerome" Then
RecipientFile = RecipientFile & FileName & ".txt"
Else
Exit Sub
End If
Dim Writer As IO.StreamWriter
Writer = New IO.StreamWriter(RecipientFile)
Writer.Write(MainRichTextBox.Text)
Writer.Close()
ShowtextRichTextBox.Text = (User & " : ") & MainRichTextBox.Text
MainRichTextBox.Clear()
End Sub
提前致谢! :*
您的以下代码只是将最新值分配(替换)到富文本框,
ShowtextRichTextBox.Text = (User & " : ") & MainRichTextBox.Text
相反,您应该附加如下文本,
ShowtextRichTextBox.Text &= (User & " : ") & MainRichTextBox.Text
此外,您可以尝试使用 RichTextBox 的内置方法来附加文本,例如 ShowtextRichTextBox.AppendText((User & " : ") & MainRichTextBox.Text)
注意:追加时,还应在新文本前添加换行符,如ShowtextRichTextBox.Text &= Environment.NewLine & (User & " : ") & MainRichTextBox.Text
.
修改后的代码,
Private Sub saveMessage()
FileName = Format(Now, "MMddyyyyhhmmss")
Dim RecipientFile As String
If CurrentRecipient = "Edward" Then
RecipientFile = RecipientFolder & FileName & ".txt"
ElseIf CurrentRecipient = "Criziel" Then
RecipientFile = RecipientFolder & FileName & ".txt"
ElseIf CurrentRecipient = "Jerome" Then
RecipientFile = RecipientFile & FileName & ".txt"
Else
Exit Sub
End If
Dim Writer As IO.StreamWriter
Writer = New IO.StreamWriter(RecipientFile)
Writer.Write(MainRichTextBox.Text)
Writer.Close()
ShowtextRichTextBox.Text &= Environment.NewLine & (User & " : ") & MainRichTextBox.Text
MainRichTextBox.Clear()
End Sub