0
將文本文件導入我的Windows窗體應用程序富文本框後,現在我想要添加搜索功能。是否有可能有多個SelectionStart值? SelectionLength將會看到相同的單詞。設置多個textbox.SelectionStart值,突出顯示搜索詞
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();