首页 > 解决方案 > 为什么我使用 textBox1.AppendText 时文本框中没有出现换行符

问题描述

我一直在尝试在 c# 中使用 ssh.net libray 制作某种终端应用程序。我已成功发送命令并接收输出,但是当我将输出附加到文本框时,新行字符消失了,尽管我可以在消息框中看到它们。我该如何解决这个问题?

SshCommand sc = client.CreateCommand(command);
sc.Execute();
textBox1.AppendText(command);
textBox1.AppendText("\n");
string answer = sc.Result;
textBox1.AppendText(answer);
MessageBox.Show(sc.Result);
textBox1.AppendText("\n");
textBox2.Clear();

当我运行 ls 命令时,我得到的输出为:

当我运行 ls 命令时,我得到的输出为:

标签: c#

解决方案


问题是您使用TextBoxwhich 不适用\n,它需要\r\n作为新行。

您可以使用RichTextBoxwhich 仅适用于 a\n作为换行符。


推荐阅读