I have some text coming from database in a Multiline textbox, how can I copy that to the clipboard so that the user can paste it into another window or file (e.g. from my application to another textbox)? OR to notepad/word file if possible.
4 Answers
Clipboard.Clear(); //Clear if any old value is there in Clipboard
Clipboard.SetText("abc"); //Copy text to Clipboard
string strClip = Clipboard.GetText(); //Get text from Clipboard

- 5,979
- 2
- 27
- 49
There is no difference in copying text from a single or multiline TextBox
to and from the clipboard using Clipboard.SetText()
(and of course Clipboard.GetText()
). A TextBox
will still contain a single String
, whether it contains line breaks or not. That's only eye candy.
From a limitations perspective, your ClipBoard.SetText()
method will always only accept one single string as well, its size only limited by and to the amount of free memory at that given time.
No special code is needed to paste this text manually into applications like Notepad or Word.
Clipboard.SetText(yourTextBox.Text);
is all you need.

- 5,097
- 3
- 39
- 55
For saving lines in text you should replace "\n" to NewLine character, as in example:
string textforClipboard = TextBox1.Text.Replace("\n", Environment.NewLine);
Clipboard.Clear();
Clipboard.SetText(textforClipboard);

- 911
- 1
- 11
- 17
System.Windows.Forms.Clipboard.SetText(..)
http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard.settext.aspx

- 7,312
- 5
- 49
- 70