private void Searchbox(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F && e.Control) { var fs = new FormContextSearch(); fs.ShowDialog(); var tb = sender as TextBox; int ind = tb.Text.IndexOf(fs.EnteredText, tb.SelectionStart, StringComparison.InvariantCultureIgnoreCase); if (ind > -1) { tb.SelectionStart = ind; tb.SelectionLength = fs.EnteredText.Length; tb.ScrollToCaret(); } } }