private void tfindFindText_TextChanged(object sender, EventArgs e) { string st = tfindFindText.Text; if (startPos == null) { startPos = new FindHistoryItem(string.Empty, rtb.SelectionStart, rtb.SelectionLength); FindHistory[startPos.Term] = startPos; } StringComparison type; if (tfindMatchCase.Checked) { type = StringComparison.Ordinal; } else { type = StringComparison.OrdinalIgnoreCase; } if (FindHistory.ContainsKey(st)) { tfindFindText.BackColor = Color.FromKnownColor(KnownColor.Window); FindHistoryItem h = FindHistory[st]; rtb.BeginUpdate(); rtb.Select(h.SelStart, h.SelLength); rtb.ScrollToCaret(); rtb.EndUpdate(); searchFrom = h.SelStart; if (st == string.Empty) { FindHistory.Clear(); tfindFindText.BackColor = Color.FromKnownColor(KnownColor.Window); } return; } if (st == string.Empty) { FindHistory.Clear(); tfindFindText.BackColor = Color.FromKnownColor(KnownColor.Window); return; } int pos = rtb.Text.IndexOf(st, searchFrom, type); if (pos != -1) { tfindFindText.BackColor = Color.FromKnownColor(KnownColor.Window); FindHistory[st] = new FindHistoryItem(st, pos, st.Length); rtb.BeginUpdate(); rtb.Select(pos, st.Length); rtb.ScrollToCaret(); rtb.EndUpdate(); searchFrom = pos; } else { searchFrom = 0; tfindFindText.BackColor = Color.FromArgb(200, 0, 0); } }
private void tfindFindText_Leave(object sender, EventArgs e) { startPos = null; FindHistory.Clear(); }