Text after the first line is lost when you modify the Multiline property of the RichTextBox control from true to false (814312)
The information in this article 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)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# 2005, Express Edition
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# .NET (2002)
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.
SYMPTOMSWhen 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.WORKAROUNDTo 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.
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbvs2005swept kbvs2005applies kbCtrl kbWindowsForms kbRichEdit kbForms kbControl kbprb KB814312 kbAudDeveloper |
---|
|