I am currently making a Notepad-Like program, but I am stumped.
I need to make a "Find a Letter/Word" Form. I have it all figured out, but I can't seem to get it to return the RichTextBox
SelectionBackColor
back to default, e.g. Color.White;
The current code I have, here:
This is the Find
Button
for Form2.cs
:
public static void Find(RichTextBox rtb,String word, Color color)
{
if(word=="")
{
return;
}
int s_start = rtb.SelectionStart, startIndex = 0, index;
while((index=rtb.Text.IndexOf(word,startIndex))!=-1)
{
rtb.Select(index, word.Length);
rtb.SelectionColor = color;
startIndex = index + word.Length;
}
rtb.SelectionStart = s_start;
rtb.SelectionLength = 0;
rtb.SelectionColor = Color.White;
}
private void button1_Click(object sender, EventArgs e)
{
Find(richtext, textBox1.Text, Color.Blue);
}
Don't mind the references(rtb, etc.)
My problem is this: It works fine at first, but if you delete the ORIGINAL "Found" text, then the SelectionColor
becomes the "Found" text's SelectionColor
Does anyone have a fix?