5

I added context menu to the richboxtext with only one function "paste". What code will paste my clipboard content (e.g. copied from Microsoft Word) to the richboxtext form? I tried with:

    private void PasteToolStripMenuItem_Click_1(object sender, EventArgs e)
    {
        richTextBox1.Text = Clipboard.GetText();
    }

but it pastes non-formatted text. How can I paste text with the formatting?

bkdev
  • 432
  • 4
  • 9
user1188235
  • 55
  • 1
  • 1
  • 4

3 Answers3

6

Got it!

Just specificy the format:

richTextBox1.Text = Clipboard.GetText(TextDataFormat.Rtf);

UPDATE

This will help you get formatted text(text only) from MS Word

jacqijvv
  • 870
  • 6
  • 17
5
DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Html);

if(richTextBox1.CanPaste(myFormat))
{
    richTextBox1.Paste(myFormat);
    return true;
}

you should change the Dataformats.Html of which type your Richtextbox should allow.

Here's the list of DataFormats : http://msdn.microsoft.com/en-us/library/system.windows.forms.dataformats.aspx

Taha Paksu
  • 15,371
  • 2
  • 44
  • 78
0

Try:

richTextBox1.selectedRtf=Clipboard.GetData(DataFormats.Rtf).ToString();
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Amritpal Singh
  • 1,765
  • 1
  • 13
  • 20