public void FindNext(string pattern) { try { RegexOptions opt = cbMatchCase.Checked ? RegexOptions.None : RegexOptions.IgnoreCase; if (!cbRegex.Checked) { pattern = Regex.Escape(pattern); } if (cbWholeWord.Checked) { pattern = "\\b" + pattern + "\\b"; } // Range range = tb.Selection.Clone(); range.Normalize(); // if (firstSearch) { startPlace = range.Start; firstSearch = false; } // range.Start = range.End; if (range.Start >= startPlace) { range.End = new Place(tb.GetLineLength(tb.LinesCount - 1), tb.LinesCount - 1); } else { range.End = startPlace; } // foreach (var r in range.GetRangesByLines(pattern, opt)) { tb.Selection = r; tb.DoSelectionVisible(); tb.Invalidate(); return; } // if (range.Start >= startPlace && startPlace > Place.Empty) { tb.Selection.Start = new Place(0, 0); FindNext(pattern); return; } MessageBox.Show("已经到文本末尾!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Select all chars of control /// </summary> public void SelectAll() { ColumnSelectionMode = false; Start = new Place(0, 0); if (tb.LinesCount == 0) { Start = new Place(0, 0); } else { end = new Place(0, 0); start = new Place(tb[tb.LinesCount - 1].Count, tb.LinesCount - 1); } if (this == tb.Selection) { tb.Invalidate(); } }