RichTextBoxFinds Enum

Definition

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

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

public enum class RichTextBoxFinds
[System.Flags]
public enum RichTextBoxFinds
type RichTextBoxFinds = 
Public Enum RichTextBoxFinds
Inheritance
RichTextBoxFinds
Attributes

Fields

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.

Examples

下面的示例搜索传递到方法的 text 参数的搜索字符串的第一个实例的 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. 该示例假定此方法位于包含名为 richTextBox1RichTextBoxForm 的类中。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

Remarks

应用程序通过调用 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.

Applies to

See also