TextDocument.MarkText(String, Int32) TextDocument.MarkText(String, Int32) TextDocument.MarkText(String, Int32) Method


Indicates whether or not the indicated text was found in the text document and creates unnamed bookmarks wherever matching text is found.

public bool MarkText (string Pattern, int vsFindOptionsValue = 0);
abstract member MarkText : string * int -> bool
Public Function MarkText (Pattern As String, Optional vsFindOptionsValue As Integer = 0) As Boolean
String String String

Required. The text pattern to find.

Int32 Int32 Int32

Optional. A vsFindOptions constant that specifies the search text options.


A Boolean value true if the marked text was found in the text document, otherwise returns false.


Sub MarkTextExample(ByVal dte As EnvDTE.DTE)  
    Dim objTD As TextDocument  

    objTD = dte.ActiveDocument.Object  
    MsgBox("Selection: " & objTD.Selection.Mode.ToString)  
    If Not objTD.MarkText("int") Then  
        MsgBox("""int"" not found.")  
        MsgBox("Note that unnamed bookmarks have been placed on lines _  
        containing ""int"".")  
    End If  
End Sub  
public void MarkTextExample(_DTE dte)  
    TextDocument td;  

    td = (TextDocument)dte.ActiveDocument.Object("");  
    MessageBox.Show ("Selection: " + td.Selection.Mode.ToString ());  
    if (td.MarkText ("int", (int)vsFindOptions.vsFindOptionsNone) ==   
        MessageBox.Show ("\"int\" not found.");  
        MessageBox.Show ("Note that unnamed bookmarks have been placed   
        on lines containing \"int\".");  
        td.ClearBookmarks ();  


MarkText searches the entire text document for Pattern, automatically creating unnamed bookmarks at each occurrence of Pattern.

The following examples look in a document (like a text file) for the word, int. If it is found, a bookmark is placed on its line. The examples then use the ClearBookmarks method to delete the bookmarks.

To run the following example, first either create or open a document that contains the word, int.

Applies to