RichTextBoxFinds 枚举

定义

指定如何在 RichTextBox 控件中执行文本搜索。Specifies how a text search is carried out in a RichTextBox control.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class RichTextBoxFinds
[System.Flags]
public enum RichTextBoxFinds
type RichTextBoxFinds = 
Public Enum RichTextBoxFinds
继承
RichTextBoxFinds
属性

字段

MatchCase 4

仅定位大小写正确的搜索文本的实例。Locate only instances of the search text that have the exact casing.

NoHighlight 8

如果找到搜索文本,不突出显示它。The search text, if found, should not be highlighted.

None 0

定位搜索文本的所有实例,而不论在搜索中找到的实例是否是全字。Locate all instances of the search text, whether the instances found in the search are whole words or not.

Reverse 16

搜索在控件文档的结尾处开始,并搜索到文档的开头。The search starts at the end of the control's document and searches to the beginning of the document.

WholeWord 2

仅定位是全字的搜索文本的实例。Locate only instances of the search text that are whole words.

示例

下面的示例在的全部内容RichTextBox中搜索传递到该方法的文本参数中的搜索字符串的第一个实例的。The following example searches the entire contents of a RichTextBox for the first instance of a search string passed into the text parameter of the method. 搜索起始位置由方法的 start 参数指定。The search starting location is specified by the start parameter of the method. 如果在中RichTextBox找到了搜索字符串, 则该方法将返回找到的文本的第一个字符的索引位置, 并突出显示找到的文本; 否则, 它将返回值-1。If the search string is found in the RichTextBox, the method returns the index location of the first character of the found text and highlights the found text; otherwise, it returns a value of -1. 该示例还在搜索中指定了与指定的搜索字符串匹配的选项。The example also specifies options in the search to match the case of the specified search string. 该示例假定将此方法放置在Form RichTextBox包含名为richTextBox1的的类中。The example assumes that this method is placed in the class of a Form that contains a RichTextBox named richTextBox1. 如果找到了搜索文本的第一个实例来查找文本的其他实例, 则在执行 "查找下一个" 类型操作时, 可以使用此示例。You can use this example when performing a "Find Next" type operation once the first instance of search text has been found to find other instances of the text.

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;
   }
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;
}

Public Function FindMyText(text As String, start As Integer) As Integer
    ' Initialize the return value to false by default.
    Dim returnValue As Integer = - 1
    
    ' Ensure that a search string has been specified and a valid start point.
    If text.Length > 0 And start >= 0 Then
        ' Obtain the location of the search string in richTextBox1.
        Dim indexToText As Integer = richTextBox1.Find(text, start, _
            RichTextBoxFinds.MatchCase)
        ' Determine whether the text was found in richTextBox1.
        If indexToText >= 0 Then
            returnValue = indexToText
        End If
    End If
    
    Return returnValue
End Function

注解

应用程序通过RichTextBox Find调用RichTextBox控件的方法在控件中查找文本。An application locates text in the RichTextBox control by calling the Find method of the RichTextBox control. 此枚举可用于指定调用Find方法时执行搜索的方式。This enumeration enables you to specify how the search is performed when the Find method is called. 可以将此枚举中的一个或多个值组合起来, 以便在调用Find方法时指定多个搜索选项。You can combine one or more values from this enumeration to specify more than one search option when calling the Find method.

适用于

另请参阅