Searches the text in a System.Windows.Forms.RichTextBox control for a string within a range of text within the control and with specific options applied to the search.
- str
- The text to locate in the control.
- start
- The location within the control's text at which to begin searching.
- end
- The location within the control's text at which to end searching. This value must be equal to negative one (-1) or greater than or equal to the start parameter.
- options
- A bitwise combination of the System.Windows.Forms.RichTextBoxFinds values.
The location within the control where the search text was found.
The RichTextBox.Find(string) method searches for the text specified in the str parameter and returns the location of the first character of the search string within the control. If the property returns a negative value, the text string being searched for was not found within the contents of the control. You can use this method to create search functionality that can be provided to the user of the control. You can also use this method to search for text to be replaced with a specific format. For example, if the user entered dates into the control, you can use the RichTextBox.Find(string) method to search for all dates in the document and replace them with the appropriate format before using the RichTextBox.SaveFile(string) method of the control.
With this version of the RichTextBox.Find(string) method, you can specify options that enable you to expand or narrow your search. You can specify options that enable you to match the casing of the search word or to search for entire words instead of partial words. By specifying the RichTextBoxFinds.Reverse enumeration in the options parameter, you can search for text from the bottom of the document to the top instead of the default top to bottom search method. This version of the RichTextBox.Find(string) method also enables you to narrow the search for text by selecting a specific start and end position within the control's text. This feature can enable you to limit the search range to a specific section of the control's text. If a value of negative one (-1) is assigned to the end parameter, the method will search until the end of the text in the System.Windows.Forms.RichTextBox for normal searches. For reverse searches, a value of negative one (-1) assigned to the end parameter indicates that text will be searched from the end of text (bottom) to the position defined by start parameter. When the start and end parameters are provided the same value the entire control is searched for normal searches. For a reverse search, the entire control is searched but the search begins at the bottom of the document and searches to the top of the document.
The RichTextBox.Find(string) methods that accept a string as a parameter cannot find text that is contained on more than one line of text within the System.Windows.Forms.RichTextBox. Performing such a search will return a value of negative one (-1).