C # How to paste formatted text from clipboard into RichTextBox
I added a context menu to the richboxtext using only one "paste" function. What code pastes clipboard content (like copied from Microsoft Word) into a richboxtext form? I tried:
private void PasteToolStripMenuItem_Click_1(object sender, EventArgs e)
{
richTextBox1.Text = Clipboard.GetText();
}
but it inserts unformatted text. How do I insert formatted text?
+3
source to share
3 answers
DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Html);
if(richTextBox1.CanPaste(myFormat))
{
richTextBox1.Paste(myFormat);
return true;
}
you should change the Dataformats.Html to the type that the Richtextbox should allow.
Here is a list of DataFormats: http://msdn.microsoft.com/en-us/library/system.windows.forms.dataformats.aspx
+5
source to share