Solved

How to copy the content of a richtextbox to a multiline textbox

Posted on 2008-10-10
11
291 Views
Last Modified: 2012-05-05
Hi all,

I want copy the text (only the text but with newline) from a richtextbox to a textbox.
the code:

TextBox.Text = RichTextBox.Text

doesn't work properly.
e.g.
Richtext:

This is
a multiline
Text

will displayed in the textbox as one line (see attached Picture)

Thanks for your help

Gerhard


form001.jpg
0
Comment
Question by:ghabiche
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 14

Expert Comment

by:Binuth
ID: 22685588
try this...

TextBox1.Text = RichTextBox1.Text.Replace("\n" , "\r\n");
0
 
LVL 1

Author Comment

by:ghabiche
ID: 22685633
Hi Binuth,

sorry, but this doesn't work.
Same behaviour as before.

0
 
LVL 14

Expert Comment

by:Binuth
ID: 22685647
set TextBox's AcceptsReturn property to true
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Author Comment

by:ghabiche
ID: 22685665
also the same
0
 
LVL 14

Expert Comment

by:Binuth
ID: 22685682
Ohh....  can you put post the output of  RichTextBox1.Text from debug window ?
0
 
LVL 8

Expert Comment

by:tiagosalgado
ID: 22685830
Try TextBox1.Text = RichTextBox1.Text.Replace("\n" , Environment.NewLine);
0
 
LVL 1

Author Comment

by:ghabiche
ID: 22685892
For better testing I have attached the Testcase
0
 
LVL 1

Author Comment

by:ghabiche
ID: 22685897
For better testing I have attached the Testcase
0
 
LVL 8

Expert Comment

by:tiagosalgado
ID: 22687057
Have you set textbox Multiline property to true?

textBox1.Text = richTextBox1.Text.Replace("\n",Environment.NewLine);
0
 
LVL 1

Accepted Solution

by:
zonkerman earned 125 total points
ID: 22694624
You are getting linfeeds from the richtextbox control.  Use the following to replace the line feeds (ascii 10) with carriage return line feeds (asciee 10 and 13) into the textbox

TextBox1.Text = RichTextBox1.Text.Replace(Chr(10), Chr(13) + Chr(10))
0
 
LVL 1

Author Closing Comment

by:ghabiche
ID: 31504942
Zonkerman, Thank you this is what I want
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question