我有这段代码
string myText = new TextRange(mainWindow.richtextbox2.Document.ContentStart,
mainWindow.richtextbox2.Document.ContentEnd).Text;
//replace two or more consecutive spaces with a single space, and
//replace two or more consecutive newlines with a single newline.
var str = Regex.Replace(myText, @"( |\r?\n)\1+", "$1", RegexOptions.Multiline);
mainWindow.Dispatcher.Invoke(new Action(() =>
mainWindow.richtextbox2.Document.Blocks.Add(new Paragraph(new
Run("Hello")))));
这已经有效,但间距仍然保留在发送的文本之间。 我该如何修复它或更新我的richtextbox?我试图消除显示文本到richtextbox的间距,如图所示
我想表明:
Hello
Hello
Hello
没有多个换行符或间距。
答案 0 :(得分:2)
文档不是字符串类型。
修改强>
string myText = new TextRange(richtextbox2.Document.ContentStart, richtextbox2.Document.ContentEnd).Text;
//replace two or more consecutive spaces with a single space, and
//replace two or more consecutive newlines with a single newline.
var str = Regex.Replace(myText, @"( |\r?\n)\1+", "$1", RegexOptions.Multiline);