Solved

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

Posted on 2008-10-10
11
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 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