RichTextBoxFinds 枚举

定义

指定如何在 RichTextBox 控件中执行文本搜索。

此枚举支持其成员值的按位组合。

C#
[System.Flags]
public enum RichTextBoxFinds
继承
RichTextBoxFinds
属性

字段

名称 说明
MatchCase 4

仅定位大小写正确的搜索文本的实例。

NoHighlight 8

如果找到搜索文本,不突出显示它。

None 0

定位搜索文本的所有实例,而不论在搜索中找到的实例是否是全字。

Reverse 16

搜索在控件文档的结尾处开始,并搜索到文档的开头。

WholeWord 2

仅定位是全字的搜索文本的实例。

示例

以下示例搜索 的整个内容 RichTextBox ,以查找传递到 方法的文本参数中的搜索字符串的第一个实例。 搜索起始位置由 方法的 start 参数指定。 如果在 中找到 RichTextBox搜索字符串,该方法将返回找到的文本的第一个字符的索引位置,并突出显示找到的文本;否则,它将返回值 -1。 该示例还指定搜索中的选项,以匹配指定搜索字符串的事例。 该示例假定此方法放置在 包含RichTextBox名为 richTextBox1Form 类中。 在找到搜索文本的第一个实例以查找文本的其他实例后,可以在执行“查找下一个”类型操作时使用此示例。

C#
public int FindMyText(string text, int start)
{
   // Initialize the return value to false by default.
   int returnValue = -1;

   // Ensure that a search string has been specified and a valid start point.
   if (text.Length > 0 && start >= 0) 
   {
      // Obtain the location of the search string in richTextBox1.
      int indexToText = richTextBox1.Find(text, start, RichTextBoxFinds.MatchCase);
      // Determine whether the text was found in richTextBox1.
      if(indexToText >= 0)
      {
         returnValue = indexToText;
      }
   }

   return returnValue;
}

注解

应用程序通过调用 Find 控件的 方法查找控件中的RichTextBoxRichTextBox文本。 通过此枚举,可以指定在调用 方法时 Find 如何执行搜索。 调用 方法时 Find ,可以组合此枚举中的一个或多个值来指定多个搜索选项。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另请参阅