I'm using a WinForms RichTextBox. It appears that when the RichTextBox is on a form,
gets converted to
. Here's a test:
I have two rich text boxes. One is richTextBox1
, which is placed on the form:
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(37, 12);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(100, 96);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
The other is rtb
, which I create on the spot. When I run this code (in the form's load event):
var rtb = new RichTextBox();
string enl = "Cheese" + Environment.NewLine + "Whiz";
rtb.Text = enl;
string ncr = rtb.Text;
MessageBox.Show(string.Format("{0}{1}{2}{3}---{4}{5}{6}{7}{8}{9}",
enl.Replace("
", "\n").Replace("
", "\r"), Environment.NewLine,
ncr.Replace("
", "\n").Replace("
", "\r"), Environment.NewLine,
Environment.NewLine,
(enl == ncr), Environment.NewLine,
enl.Contains(Environment.NewLine), Environment.NewLine,
ncr.Contains(Environment.NewLine)));
/*
Cheese
Whiz
Cheese
Whiz
---
True
True
True
*/
richTextBox1.Text = enl;
string ncr2 = richTextBox1.Text;
MessageBox.Show(string.Format("{0}{1}{2}{3}---{4}{5}{6}{7}{8}{9}",
enl.Replace("
", "\n").Replace("
", "\r"), Environment.NewLine,
ncr2.Replace("
", "\n").Replace("
", "\r"), Environment.NewLine,
Environment.NewLine,
(enl == ncr2), Environment.NewLine,
enl.Contains(Environment.NewLine), Environment.NewLine,
ncr2.Contains(Environment.NewLine)));
/*
Cheese
Whiz
Cheese
Whiz
---
False
True
False
*/
The RichTextBox seems to be exhibiting some strange behavior. When I put text containing a
into the box I just created, it stays the same (still contains the
). However, when I put text containing an
into the box on the form, the
gets turned into
.
My Questions: Is there a reason for this behavior (
->
)? Is this behavior documented somewhere? Can I count on it always being this way?
The case I posted here is my attempt at getting to the bottom of a problem I've been having with one of my forms in a different project, so I'd appreciate any input regarding this issue.
See Question&Answers more detail:
os