RichTextBoxFinds RichTextBoxFinds RichTextBoxFinds RichTextBoxFinds Enum

定义

指定如何在 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
继承
RichTextBoxFindsRichTextBoxFindsRichTextBoxFindsRichTextBoxFinds
属性

字段

MatchCase MatchCase MatchCase MatchCase 4

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

NoHighlight NoHighlight NoHighlight NoHighlight 8

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

None None None None 0

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

Reverse Reverse Reverse Reverse 16

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

WholeWord WholeWord WholeWord 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名为richTextBox1The 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.

适用于

另请参阅