Click here to Skip to main content
15,790,267 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have used the appendText() function to append text to RichTextBox Now How do I clear the RichTextBox's Text

Thanks in Advance.
Sergey Alexandrovich Kryukov 28-Jul-11 1:49am    
Tag it properly? WPF, Forms, what?!

Use Undo[^]
Share this answer
Sergey Alexandrovich Kryukov 28-Jul-11 2:01am    
Correct, my 5, but if undo is too late to do (due to some other operations which does not allow to figure out which operations should be undone), there is a universal way of removing added data; please see my solution.
Here is what you should not do: do not calculate new text for the instance of RichTextBox and do not assign it to the property Text. Do not try to do something like that with the property Rtf. (This is applicable to System.Windows.Forms.RichTextBox only, you cannot do it for WPF System.Windows.Controls.RichTextBox.)

Here is what you should do: select the text you need using the properly SelectionStart and SelectionEnd, then assign the property SelectedText to string.Empty.

Also, pay attention: these controls have Undo functionality; you can use it.


Please, always tag UI library you want to use, don't make experts doing double work!

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900