RichTextBox Fun?
-
The following code works just fine on my "test" form, but when i put the code in the REAL application i get a selection rectangle, rather than the nice text color change i get with this code: richTextBox1.AppendText("This" + System.Environment.NewLine); richTextBox1.AppendText("seems" + System.Environment.NewLine); richTextBox1.AppendText("to" + System.Environment.NewLine); richTextBox1.AppendText("work." + System.Environment.NewLine); string mySearchLetters = textBox1.Text; int index = richTextBox1.Find(mySearchLetters); label1.Text = mySearchLetters + " was found in pos " + index.ToString(); if (index >= 0) richTextBox1.SelectionColor = System.Drawing.Color.Orange; I'm thinking that maybe there is a "property" set on the real application that prevents this code from working but i can not find it. i compare the control properties, line-for-line and they seem to be identical. Any ideas?
-
The following code works just fine on my "test" form, but when i put the code in the REAL application i get a selection rectangle, rather than the nice text color change i get with this code: richTextBox1.AppendText("This" + System.Environment.NewLine); richTextBox1.AppendText("seems" + System.Environment.NewLine); richTextBox1.AppendText("to" + System.Environment.NewLine); richTextBox1.AppendText("work." + System.Environment.NewLine); string mySearchLetters = textBox1.Text; int index = richTextBox1.Find(mySearchLetters); label1.Text = mySearchLetters + " was found in pos " + index.ToString(); if (index >= 0) richTextBox1.SelectionColor = System.Drawing.Color.Orange; I'm thinking that maybe there is a "property" set on the real application that prevents this code from working but i can not find it. i compare the control properties, line-for-line and they seem to be identical. Any ideas?
I take it your trying to highlight the position and length of the string you typed in? This code won't work because your not changing the .SelectStart and .SelectionLength properties to actually select the string you want to change with .SelectionColor.
richTextBox1.SelectionStart = pos; richTextBox1.SelectionLength = mySearchLetters.Length; richTextBox1.SelectionColor = Color.Orange;
RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
I take it your trying to highlight the position and length of the string you typed in? This code won't work because your not changing the .SelectStart and .SelectionLength properties to actually select the string you want to change with .SelectionColor.
richTextBox1.SelectionStart = pos; richTextBox1.SelectionLength = mySearchLetters.Length; richTextBox1.SelectionColor = Color.Orange;
RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
It turns out the solution was even simpler .. there WAS a property that was messing things up. All i had to do was set HideSelection to true !!! The pretty orange text was hidden under the selection rectangle ... go figure ... lol. Thanks for responding, Dave.