For the small application Im working on (the snippets manager) Im implementing find & replace. The code I have finds the string properly, but it isn't highlighting the text, even though I tell it to. Here's the code for Find
csharp
public static void Find(string text, bool matchCase, RichTextBox rtb, System.Windows.Forms.Button btn)
{
try
{
int startPos;
StringComparison type;
type = matchCase == true ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
startPos = rtb.Text.IndexOf(text, type);
if (!(startPos > 0))
{
MessageBox.Show("Search text: '" + text + "' could not be found", "Text Not Found", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
else
{
rtb.Select(startPos, text.Length);
rtb.ScrollToCaret();
btn.Enabled = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Search Error");
}
}
That code finds the text, even scrolls the caret to the text, but it isn't highlighting it. Any ideas?