Microsoft Knowledge Base Email Alertz

KBAlertz.com: (814312) - When you type multiple lines of text in a RichTextBox control, and then modify the Multiline property from True to False , you lose the text in the RichTextBox after the first line. When you modify the Multiline property, only the first line exists in...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 814312 - Last Review: December 3, 2007 - Revision: 2.9

Text after the first line is lost when you modify the Multiline property of the RichTextBox control from true to false

On This Page

Beta Information
This article discusses a Beta release of a Microsoft product. The information in this article is provided as-is and is subject to change without notice.

No formal product support is available from Microsoft for this Beta product. For information about how to obtain support for a Beta release, see the documentation that is included with the Beta product files, or check the Web location from which you downloaded the release.

SYMPTOMS

When you type multiple lines of text in a RichTextBox control, and then modify the Multiline property from True to False, you lose the text in the RichTextBox after the first line. When you modify the Multiline property, only the first line exists in the RichTextBox. However, when you modify the Multiline property from True to False for a RichTextBox, all the text of the control is appended to the first line.

WORKAROUND

To work around this problem, save the text in the RichTextBox before you toggle the Multiline property. After you modify the Multiline property, append all the text lines into the first line, and then assign the text back to the RichTextBox. To do this, use the following code:

Visual Basic .NET or Visual Basic 2005 Code
      ' Create an Array
      Dim myStrArr() As String
      myStrArr = RichTextBox1.Text.Split(vbLf.ToString)

      ' Set Multiline Property value to False
      RichTextBox1.Multiline = False

      Dim idx As Integer
      RichTextBox1.Text = ""
      For idx = 0 To myStrArr.Length - 1
         RichTextBox1.Text += myStrArr(idx) & " "
      Next idx
Visual C# .NET or Visual C# 2005 Code
     // Create a string Array.
     string []myStrArr;
     myStrArr = richTextBox1.Text.Split('\n');

     // Set multiline property value to false.
     richTextBox1.Multiline = false;
     int idx;
     richTextBox1.Text = "";
     for(idx = 0; idx < myStrArr.Length ;idx++)
     {
	       richTextBox1.Text += myStrArr[idx]+ " ";
     }

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  2. Create a Windows application by using Visual Basic 2005, Visual Basic .NET, Visual C# 2005, or Visual C# .NET.

    By default, Form1 is created.
  3. Drag a RichTextBox control to Form1.
  4. Drag a Button control to Form1.
  5. Double-click Button1, and then add the following code to the Button1_Click event handler:
    Visual Basic .NET or Visual Basic 2005 Code
    RichTextBox1.Multiline = False
    Visual C# .NET or Visual C# 2005 Code
    richTextBox1.Multiline = false;
  6. On the Build menu, click Build Solution.
  7. Press the F5 key to run the project.
  8. Type two or three lines of text in the RichTextBox, and then click Button1.

REFERENCES

For more information, visit the following MSDN Web site:

Introduction to the Windows Forms RichTextBox Control
http://msdn2.microsoft.com/en-us/library/aa983713(VS.71).aspx (http://msdn2.microsoft.com/en-us/library/aa983713(VS.71).aspx)

APPLIES TO
  • Microsoft .NET Framework 2.0
  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Visual C# 2005 Express Edition
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
Keywords: 
kbvs2005swept kbvs2005applies kbctrl kbwindowsforms kbrichedit kbforms kbcontrol kbprb KB814312
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please