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
user1188235
source
to share
3 answers
Got it!
Just specify the format:
richTextBox1.Text = Clipboard.GetText(TextDataFormat.Rtf);
UPDATE
This will help you get rich text (text only) from MS Word
+5
jacqijvv
source
to share
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
Taha paksu
source
to share
Try:
richTextBox1.selectedRtf=Clipboard.GetData(DataFormats.Rtf).ToString();
0
Amritpal singh
source
to share