将文本文件导入我的 Windows 窗体应用程序富文本框后,我现在想添加搜索功能。是否可以有多个 SelectionStart 值?SelectionLength 将是相同的,因为它是相同的单词。
        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();