System.Windows.Forms.RichTextBox.Find Method

Searches the text in a System.Windows.Forms.RichTextBox control for a string.


public int Find (string str)


The text to locate in the control.


The location within the control where the search text was found or -1 if the search string is not found or an empty search string is specified in the str parameter.


The RichTextBox.Find(string) method searches for the text specified in the str parameter and returns the location of the first character 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 could 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.


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).


Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0,