OmniOwl
OmniOwl

Reputation: 5709

How do you clear a WPF RichTextBox?

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.

I've tried looking for a Text property, and I've tried to look through the Document property as well, but to no avail.

What I am missing? The box needs to be cleared, like you can do with a textbox.Clear() call.

Upvotes: 13

Views: 22550

Answers (4)

Elias Santos
Elias Santos

Reputation: 17

The correct way to do this for Windows Forms is to do richTextBox.ResetText();

Upvotes: 0

Nima Soroush
Nima Soroush

Reputation: 12834

If you are adding some controls into the richTextBox (e.g. below):

LinkLabel link = new LinkLabel();
richTextBox1.Controls.Add(link);

you have to use

richTextBox1.Controls.Clear();

to remove all controls.

Upvotes: 1

user2303237
user2303237

Reputation: 9

You could just do richTextBox.Text = "";, too.

Upvotes: -4

Mike Precup
Mike Precup

Reputation: 4218

You can clear a RichTextBox with richTextBox.Document.Blocks.Clear();

Upvotes: 42

Related Questions