RichTextBoxFinds 枚举

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

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

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
<FlagsAttribute> _
Public Enumeration RichTextBoxFinds
用法
Dim instance As RichTextBoxFinds
[FlagsAttribute] 
public enum RichTextBoxFinds
[FlagsAttribute] 
public enum class RichTextBoxFinds
/** @attribute FlagsAttribute() */ 
public enum RichTextBoxFinds
FlagsAttribute 
public enum RichTextBoxFinds

成员

  成员名称 说明
MatchCase 仅定位大小写正确的搜索文本的实例。 
NoHighlight 如果找到搜索文本,不突出显示它。 
None 定位搜索文本的所有实例,而不论在搜索中找到的实例是否是全字。 
Reverse 搜索在控件文档的结尾处开始,并搜索到文档的开头。 
WholeWord 仅定位是全字的搜索文本的实例。 

备注

应用程序通过调用 RichTextBox 控件的 Find 方法来在 RichTextBox 控件中定位文本。该枚举使您能够在调用 Find 方法时指定如何执行搜索。可以合并该枚举的一个或多个值,以在调用 Find 方法时指定一个以上的搜索选项。

示例

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

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
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 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.get_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;
} //FindMyText

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

System.Windows.Forms 命名空间
RichTextBox 类
RichTextBox.Find