How to set the cursor in front of the found word in richTextBox? I want to do a search with the button "Find more ...". While there is a selection of matches.
if (txtB_Find.Text.Length > 0) { int indexToText = rTB_Result.Find(txtB_Find.Text); if (indexToText >= 0) { int i = 0; MatchCollection allIp = Regex.Matches(rTB_Result.Text, txtB_Find.Text); foreach (Match ip in allIp) { rTB_Result.SelectionStart = ip.Index; rTB_Result.SelectionLength = ip.Length; rTB_Result.SelectionBackColor = Color.FromArgb(255, 160, 122); i = i + 1; } MessageBox.Show("Найдено совпадений: " + i, txtB_Find.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Искомый элемент НЕ найден!", txtB_Find.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
rTB_Result.SelectionLength = 0instead ofip.Length- nick_n_arichTextBox.SelectionStart = позиция, and Length is there because rTB_Result is not entirely clear what. - nick_n_a