Copy selected text from RichTextBox

I searched on the net but cannot find a way to copy / cut / paste selected text from RichTextBox .

Even MSDN has no answer. The code they provide does not work: Copy() only works with TextBox, not RichTextBoxes.

+3
c # winforms richtextbox
source share
4 answers

If you are using .NET 3.0 or later, you can always use Clipboard.SetText ()

It was useful for me to use Clipboard when I need everything in a richTextBox without having to select everything first or when I need to change the line:

 string text = "Summary:" + Environment.NewLine + this.richTextBoxSummary.Text; Clipboard.SetText(text); 
+5
source share

if i copy this method:

 Clipboard.SetText(richTextBox1.SelectedRtf, TextDataFormat.Rtf); 

I can’t paste into notebook

if i copy this method:

 Clipboard.SetText(richTextBox1.SelectedText, TextDataFormat.UnicodeText); 

it works in word and notepad but inserts into a word without forming

 richTextBox1.Copy(); 

works in Word and notepad, but I cannot change the string value.

How to copy a usually formatted string to the clipboard?

PS I found

 DataObject dto = new DataObject(); dto.SetText(mesrtf, TextDataFormat.Rtf); dto.SetText(mes, TextDataFormat.UnicodeText); Clipboard.Clear(); Clipboard.SetDataObject(dto); 

working

+8
source share

richTextBox1.SelectAll ();

richTextBox1.Copy ();

/ *

selects all txt in the field and saves formatting when and paste it again into notepad

* /

-one
source share

in wpf just

 richTextBox1.Copy(); richTextBox1.Paste(); 
-2
source share

All Articles