Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear text content in RichTextBox

Tags:

c#

wpf

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); 
like image 508
Yasser Avatar asked May 29 '12 19:05

Yasser


People also ask

What is difference between RichTextBox and TextBox?

The RichTextBox is similar to the TextBox, but it has additional formatting capabilities. Whereas the TextBox control allows the Font property to be set for the entire control, the RichTextBox allows you to set the Font, as well as other formatting properties, for selections within the text displayed in the control.

How do I add text to RichTextBox?

Step 2: Drag the RichTextBox control from the ToolBox and drop it on the windows form. You are allowed to place a RichTextBox control anywhere on the windows form according to your need. Step 3: After drag and drop you will go to the properties of the RichTextBox control to add text in the RichTextBox control.

What is Rich TextBox control?

The RichTextBox control enables you to display or edit flow content including paragraphs, images, tables, and more. This topic introduces the TextBox class and provides examples of how to use it in both Extensible Application Markup Language (XAML) and C#.


2 Answers

Use the following:

_richTextBox.Document.Blocks.Clear(); 
like image 190
Curtis Avatar answered Oct 02 '22 09:10

Curtis


This is a simple way of doing it.

        public void Clear()         {             richTextBox1.SelectAll();              richTextBox1.Selection.Text = "";         } 
like image 45
Adiel Yaacov Avatar answered Oct 02 '22 11:10

Adiel Yaacov