Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How can I paste formatted text from clipboard to the RichTextBox

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?

like image 979
user1188235 Avatar asked Mar 17 '12 10:03

user1188235


1 Answers

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

like image 145
jacqijvv Avatar answered Nov 14 '22 22:11

jacqijvv