Export (0) Print
Expand All
Expand Minimize
0 out of 1 rated this helpful - Rate this topic

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.

[Visual Basic]
<Flags>
<Serializable>
Public Enum RichTextBoxFinds
[C#]
[Flags]
[Serializable]
public enum RichTextBoxFinds
[C++]
[Flags]
[Serializable]
__value public enum RichTextBoxFinds
[JScript]
public
   Flags
 Serializable
enum RichTextBoxFinds

Remarks

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.

Members

Member name Description Value
MatchCase Locate only instances of the search text that have the exact casing. 4
NoHighlight The search text, if found, should not be highlighted. 8
None Locate all instances of the search text, whether the instances found in the search are whole words or not. 0
Reverse The search starts at the end of the control's document and searches to the beginning of the document. 16
WholeWord Locate only instances of the search text that are whole words. 2

Example

[Visual Basic, C#, C++] 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.

[Visual Basic] 
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


[C#] 
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;
}


[C++] 
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;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

System.Windows.Forms Namespace | RichTextBox | RichTextBox.Find

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.