Copy and Pasting RTF to non RTF supported program

G

Grant Smith

I've got an application that I can copy some text out of the
RichTextBox control. I would like to keep the formatting so I'm able
to copy it to the Clipboard with RTF formatting. I have no trouble
pasting the formatted text into wordpad (which supports RTF formatting)
but it won't paste into notepad (no RTF support). I know that if I
copy something in wordpad with RTF formatting and then paste it into
notepad the text will paste. What am I missing that will let me paste
RTF formatted text into an application that doesn't support RTF
formatting?

Here's the code I have to copy:
Clipboard.SetText(rtxtOutput.SelectedRtf,
TextDataFormat.Rtf);

I've also tried
String spareData = rtxtOutput.SelectedRtf;

DataObject newData = new DataObject(DataFormats.Rtf,
spareData);

Clipboard.SetDataObject(newData, true);
But neither will allow me to paste RTF formatted text into a non-RTF
supported application.

Anyone able to help me?
 
P

Peter Duniho

[...] I know that if I
copy something in wordpad with RTF formatting and then paste it into
notepad the text will paste. What am I missing that will let me paste
RTF formatted text into an application that doesn't support RTF
formatting?

Typically, the solution to this is that you have to copy both RTF and
plain text data to the clipboard. Generally speaking, you put each data
format suitable for the data being copied on the clipboard. Then
applications pasting the data choose their preferred format, falling back
on other formats as necessary.

The documentation for .NET support of the clipboard hints at an ability to
do conversions on the fly from clipboard data but a) I have not found the
..NET Clipboard class to always work as advertised, and b) I think this
would only help when pasting into a .NET application. If you want to
support plain text pasting into other applications, you need to include
that format among the data formats you put on the clipboard.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top