After getting the text in the RichTextBox I want to clear the text. How can I do that?
TextRange txt = new TextRange(richtxtSNotice.Document.ContentStart, richtxtSNotice.Document.ContentEnd);
MessageBox.Show(txt.Text);
使用以下内容:
_richTextBox.Document.Blocks.Clear();
This is a simple way of doing it.
public void Clear()
{
richTextBox1.SelectAll();
richTextBox1.Selection.Text = "";
}
Try to create a TextRange
with RichBoxText
content, then set Text
to empty string:
TextRange txt = new TextRange(richtxtSNotice.Document.ContentStart, richtxtSNotice.Document.ContentEnd);
txt.Text = "";
I found that clearing the richTextBox didn't always remove all of the text from the richTextBox using richTextBox.Text = ""; or richTextBox.Clear(); Only the first few lines were cleared.
To fix this issue, I included the Update() function call solved this issue.
richTextBox.Clear();
followed by
richTextBox.Update();
to reliably clear the richTextBox.
To clear all content of richtext box you can use the following code
richTextBox1->SelectAll();
richTextBox1->Clear();
easiest way I know how is to put
(your richTextbox name).text = "";
that tells it to replace anything in the textbox field with blank code. I'm sure there are other ways to do it too though.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.