1

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?

Fuzz Evans
  • 2,893
  • 11
  • 44
  • 63
  • You could write you own method and have it call on maybe the double click event. Or you could even do 'Ctrl + V' combo key press event. There is no setting for RTB's that remove formatting. When you say formatting, what do you mean exactly? – Botonomous Jun 04 '12 at 18:43
  • I mean that when you copy something that is big and bold letters on a website, then paste it into the form it still has big bold letters, I would like it to be a standard text, not big and bold. Sounds Like I'll have to make a method to format it. – Fuzz Evans Jun 04 '12 at 18:48
  • Like Magnus said below, save the capture the clipboard to a string or Var, then move the string over to your richtextbox. That should work. --Testing now-- – Botonomous Jun 04 '12 at 18:49
  • That works. I did not have a problem with the formatting being carried over when storing the clipboard data into a string, then over to the RTB. If your going to use the event, and need help with a complete method, np just ask. – Botonomous Jun 04 '12 at 19:01

1 Answers1

1

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);
Magnus Johansson
  • 28,010
  • 19
  • 106
  • 164
  • This will work, but I think the harder problem is detecting when a paste has occurred. See this SO article to help you with that: http://stackoverflow.com/questions/5618162/detecting-if-paste-event-occurred-inside-a-rich-text-box – Ethan Brown Jun 04 '12 at 18:51
  • I dont think he is needed to detect when the paste occurs. Alternatively, the OP could simply contorl when the paste occurs; as in on the richtextbox Double click event etc...Thats what I would recommend. – Botonomous Jun 04 '12 at 18:55