Click here to Skip to main content
15,888,802 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 22: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);
 
Share this answer
 
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
 
Share this answer
 
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)
 
Share this answer
 
richTextBox1.Cut();

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

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


C#
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.
 
Share this answer
 
If RichTextBox1.SelectedText <> "" Then

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

End If
 
Share this answer
 
SQL
If RichTextBox1.SelectedText <> "" Then

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

      End If
 
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