Click here to Skip to main content
14,695,620 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using this code but its not working

richTextBox1.SelectedText.Replace(richTextBox1.SelectedText,"");


Its on the click event of a button. Thanks.
Posted
Updated 23-Jan-11 23:19pm
v2
Comments
Toli Cuturicu 24-Jan-11 4:43am
   
Press the DEL key.

use given code
richTextBox1.SelectedText = "";

or you can also use
richTextBox1.Text = richTextBox1.Text.Remove(richTextBox1.SelectionStart, richTextBox1.SelectionLength);
   
v2
Comments
Drusilla Bgabo 24-Jan-11 5:41am
   
they both work. thanks Ravi.
RaviRanjanKr 24-Jan-11 6:45am
   
you are welcome
Doesn't
richTextBox1.SelectedText = "";

work?

Cheers
   
Comments
Member 12136378 24-Nov-15 4:25am
   
thanks for your code ,but i need to replace all selected text in the rich text box
F6.RichTextBox1.Focus()


SendKeys.Send(TextBox4.Text)
   
richTextBox1.Cut();

It will work.
   
Visual Studio Express 2012, C#, WPF (not Form) richtextbox

richTextbox1.Selection.Text = ""; // To clear selected text


richTextbox1.Selection.Text = "Your Text"; // To clear and replace selected text.


This is my first reply. I'm starting to learn WPF in place of the standard Forms. RichTextBox can be a challenge.
   
If RichTextBox1.SelectedText <> "" Then

RichTextBox1.SelectedText = ""
Else
RichTextBox1.Clear()

End If
   
If RichTextBox1.SelectedText <> "" Then

          RichTextBox1.SelectedText = ""
      Else
          RichTextBox1.Clear()

      End If
   

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