Fuzz Evans
Fuzz Evans

Reputation: 2943

How can I auto-format text pasted into rich textbox?

I have a notes program that I use to document cases while working, however when I copy and paste data from other windows it pastes it in with the formating from the site. Is there a setting for rich text boxes (and text boxes in general) that will remove any formatting and put only the text into the textbox? If not can do I have to use a method that looks at the clipboard contents and sends the string to a specific font/size etc?

Upvotes: 1

Views: 3388

Answers (1)

Magnus Johansson
Magnus Johansson

Reputation: 28325

You should be able to get the unformatted string by specifying the TextDataFormat and set it to Text:

var stringToPasteIn = Clipboard.GetText(TextDataFormat.Text);

Or letting the RichTextBox do it for you automagically using its DataFormats options:

DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Text);
richTextBox1.Paste(myFormat);

Upvotes: 1

Related Questions