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, ri
To clear all content of richtext box you can use the following code
richTextBox1->SelectAll();
richTextBox1->Clear();
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.
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.
This is a simple way of doing it.
public void Clear()
{
richTextBox1.SelectAll();
richTextBox1.Selection.Text = "";
}
Use the following:
_richTextBox.Document.Blocks.Clear();