你如何清除 WPF RichTextBox?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16125721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you clear a WPF RichTextBox?
提问by OmniOwl
Whenever I do richtextbox1.Clear()it says the method doesn't exist. And it's pretty much the only solution I get, everywhere I go.
每当我这样做时,richtextbox1.Clear()都会说该方法不存在。无论我走到哪里,这几乎都是我得到的唯一解决方案。
I've tried looking for a Textproperty, and I've tried to look through the Documentproperty as well, but to no avail.
我试过寻找Text房产,我也试过查看Document房产,但无济于事。
What I am missing? The box needs to be cleared, like you can do with a textbox.Clear()call.
我缺少什么?需要清除该框,就像您可以textbox.Clear()拨打电话一样。
回答by Mike Precup
You can clear a RichTextBox with richTextBox.Document.Blocks.Clear();
您可以清除 RichTextBox richTextBox.Document.Blocks.Clear();
回答by Nima Soroush
If you are adding some controls into the richTextBox (e.g. below):
如果您在 RichTextBox 中添加一些控件(例如下面):
LinkLabel link = new LinkLabel();
richTextBox1.Controls.Add(link);
you have to use
你必须使用
richTextBox1.Controls.Clear();
to remove all controls.
删除所有控件。
回答by Elias Santos
The correct way to do this for Windows Forms is to do richTextBox.ResetText();
为 Windows 窗体执行此操作的正确方法是执行 richTextBox.ResetText();
回答by user2303237
You could just do richTextBox.Text = "";, too.
你也可以这样做richTextBox.Text = "";。

