Exemple #1
0
 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);
     }
 }
Exemple #2
0
 /// <summary>
 /// Expands range from first char of Start line to last char of End line
 /// </summary>
 public void Expand()
 {
     Normalize();
     start = new Place(0, start.iLine);
     end   = new Place(tb.GetLineLength(end.iLine), end.iLine);
 }