After importing a text file into my Windows Form Application Rich Text box, I now want to add the search function. Is it possible to have multiple SelectionStart values? The SelectionLength will be the same seeing that its the same word.
string textfield = TextField.Text;
string searchword = searchbox.Text;
int found=0;
TextField.SelectionLength = searchword.Length;
TextField.SelectionBackColor = Color.LightBlue;
for (int y = 0; y < textfield.Length; y++)//Goes through whole string
{
if (searchword[0] == textfield[y])//Looks for first character
{
for (int x = 0; x < searchword.Length; x++)//Checks if rest of characters match
{
if (searchword[x] == textfield[y + x])
{
found++;
}
else
break;
}
}
if (found == searchword.Length)
{
TextField.SelectionStart = y;//////Want to have multiple of these
}
found=0;
}
TextField.Focus();
No you can’t. But you can change the back color of a selected text, for example. Start by selecting a word. Then do this
To clear the all the markings, just select the whole text and set the back color to white (assuming that you are not using back colors otherwise).
In the example I am assuming that you are using
Regex. You would find the words with: