Export (0) Print
Expand All
Expand Minimize

RichTextBoxFinds Enumeration

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.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[FlagsAttribute] 
public enum RichTextBoxFinds
/** @attribute FlagsAttribute() */ 
public enum RichTextBoxFinds
FlagsAttribute 
public enum RichTextBoxFinds

 Member nameDescription
MatchCaseLocate only instances of the search text that have the exact casing. 
NoHighlightThe search text, if found, should not be highlighted. 
NoneLocate all instances of the search text, whether the instances found in the search are whole words or not. 
ReverseThe search starts at the end of the control's document and searches to the beginning of the document. 
WholeWordLocate only instances of the search text that are whole words. 

An application locates text in the RichTextBox control by calling the Find method of the RichTextBox control. This enumeration enables you to specify how the search is performed when the Find method is called. You can combine one or more values from this enumeration to specify more than one search option when calling the Find method.

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. The search starting location is specified by the start parameter of the method. 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. 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.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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft