How to clear text content in RichTextBox

前端 未结 6 703
眼角桃花
眼角桃花 2020-12-15 02:53

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         


        
相关标签:
6条回答
  • 2020-12-15 03:18

    To clear all content of richtext box you can use the following code

    richTextBox1->SelectAll();
    richTextBox1->Clear();
    
    0 讨论(0)
  • 2020-12-15 03:23

    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 = "";
    
    0 讨论(0)
  • 2020-12-15 03:23

    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.

    0 讨论(0)
  • 2020-12-15 03:25

    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.

    0 讨论(0)
  • 2020-12-15 03:28

    This is a simple way of doing it.

            public void Clear()
            {
                richTextBox1.SelectAll();
    
                richTextBox1.Selection.Text = "";
            }
    
    0 讨论(0)
  • 2020-12-15 03:35

    Use the following:

    _richTextBox.Document.Blocks.Clear();
    
    0 讨论(0)
提交回复
热议问题