Clipboard.SetText not copying new line characters properly

1.2k views Asked by At

In VB 2005, I'm using ClipBoard.SetText to copy the contents of a RichTextBox to the Clipboard:

My.Computer.Clipboard.SetText(RichTextBox1.Text)

The RichTextBox has multiple lines. The problem I'm having is that after performing this operation and pasting in Notepad, the new line characters don't seem to be recognized by Notepad (at least, not in the Courier New font). The text appears on one line, as if there weren't any new line characters.

I've tried using vbNewline, ControlChars.NewLine, and Chr(13) as the new line characters in my text, but the result is the same. I've read some articles on this topic, but I haven't found anything more useful than "replace '\n' with '\r\n'"; there are no instances of '\n' within my text, and implementing the replacement had no effect. As with other articles I read, pasting into other word processing programs has no problems.

I'm not quite sure how to make pasting into Notepad work properly here. Please help!

1

There are 1 answers

0
Idle_Mind On

You can do what Mathemats suggests with:

My.Computer.Clipboard.SetText(RichTextBox1.Text.Replace(vbLf, vbCrLf))

Then it should work for NotePad...