The text expression to search for.
The occurrence of the searched expression on the current page. Set the occurrence to 0 if you are searching for all occurrences of a given text. Set the occurrence to 1 if you are searching for the first occurrence, set it to 2 for the second etc.
Set this parameter to true if you want to apply case-sensitive search, otherwise set it to false.
Set this parameter to true if you want to search for the whole words only, otherwise set it to false.
Example





In This Topic
GdPicture14.WPF Namespace / GdViewer Class / SearchText Method / SearchText(String,Int32,Boolean,Boolean) Method

SearchText(String,Int32,Boolean,Boolean) Method

In This Topic
Searches for and highlights an occurrence of a given text expression within the current page of the document displayed in the GdViewer control according to the parameters you have specified. If the format of the displayed document is other than supported text-based formats, which currently are DOCX, TXT, RTF and PDF, this method will fail.

Be aware that this method uses InvariantCulture comparison when searching. It means, that characters are comparing using culture-sensitive sort rules and the invariant culture, in other words this method respects accents when searching.

Please note that currently defined highlighted regions are enriched with those recognized by this search. You can use the RemoveAllRegions method before starting new search to ensure the previously defined regions will remove.

Syntax
'Declaration
 
Public Overloads Function SearchText( _
   ByVal Text As String, _
   ByVal Occurrence As Integer, _
   ByVal CaseSensitive As Boolean, _
   ByVal WholeWords As Boolean _
) As Boolean
public bool SearchText( 
   string Text,
   int Occurrence,
   bool CaseSensitive,
   bool WholeWords
)
public function SearchText( 
    Text: String;
    Occurrence: Integer;
    CaseSensitive: Boolean;
    WholeWords: Boolean
): Boolean; 
public function SearchText( 
   Text : String,
   Occurrence : int,
   CaseSensitive : boolean,
   WholeWords : boolean
) : boolean;
public: bool SearchText( 
   string* Text,
   int Occurrence,
   bool CaseSensitive,
   bool WholeWords
) 
public:
bool SearchText( 
   String^ Text,
   int Occurrence,
   bool CaseSensitive,
   bool WholeWords
) 

Parameters

Text
The text expression to search for.
Occurrence
The occurrence of the searched expression on the current page. Set the occurrence to 0 if you are searching for all occurrences of a given text. Set the occurrence to 1 if you are searching for the first occurrence, set it to 2 for the second etc.
CaseSensitive
Set this parameter to true if you want to apply case-sensitive search, otherwise set it to false.
WholeWords
Set this parameter to true if you want to search for the whole words only, otherwise set it to false.

Return Value

true if the given text expression has been found on the current page according to the specified parameters, otherwise false. The GetStat method can be subsequently used to determine if this method has been successful.
Remarks
This method is only useful for text-based document formats, like DOCX, TXT, RTF and PDF.

Just to inform you, that this method respects accents when searching. You can use the overloaded SearchText(String,Int32,Boolean,Boolean,Boolean) method for searching not respecting accents.

Be aware that regions determined by this search enrich the currently defined highlighted regions.

Example
How to search for given text within the current page using different parameters.
This example shows you the number of highlighted regions after the successful search.
'We assume that the GdViewer1 control has been properly integrated.
If GdViewer1.DisplayFromFile("") = GdPictureStatus.OK Then
    Dim text_to_find As String = "GdPicture"
    GdViewer1.RemoveAllRegions()
    Dim text_found As Boolean = GdViewer1.SearchText(text_to_find, 0, True, True)
    If GdViewer1.GetStat() = GdPictureStatus.OK Then
        If text_found Then
            GdViewer1.Redraw()
            MessageBox.Show("The number of highlighted regions: " + GdViewer1.RegionCount().ToString(), "GdViewer.SearchText")
        Else
            MessageBox.Show("The given text has not been found.", "GdViewer.SearchText")
        End If
    Else
        MessageBox.Show("The search process has failed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SearchText")
    End If
Else
    MessageBox.Show("The file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SearchText")
End If
//We assume that the GdViewer1 control has been properly integrated.
if (GdViewer1.DisplayFromFile("") == GdPictureStatus.OK)
{
    string text_to_find = "GdPicture";
    GdViewer1.RemoveAllRegions();
    bool text_found = GdViewer1.SearchText(text_to_find, 0, true, true);
    if (GdViewer1.GetStat() == GdPictureStatus.OK)
    {
        if (text_found)
        {
            GdViewer1.Redraw();
            MessageBox.Show("The number of highlighted regions: " + GdViewer1.RegionCount().ToString(), "GdViewer.SearchText");
        }
        else
            MessageBox.Show("The given text has not been found.", "GdViewer.SearchText");
    }
    else
        MessageBox.Show("The search process has failed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SearchText");
}
else
    MessageBox.Show("The file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SearchText");
This example centres the viewer on the current rectangle of area selection after the successful search.
'We assume that the GdViewer1 control has been properly integrated.
If GdViewer1.DisplayFromFile("") = GdPictureStatus.OK Then
    Dim text_to_find As String = "GdPicture"
    GdViewer1.ClearRect()
    Dim text_found As Boolean = GdViewer1.SearchText(text_to_find, 1, True, True)
    If GdViewer1.GetStat() = GdPictureStatus.OK Then
        If text_found AndAlso GdViewer1.IsRect() Then
            GdViewer1.CenterOnRect()
        Else
            MessageBox.Show("The given text has not been found.", "GdViewer.SearchText")
        End If
    Else
        MessageBox.Show("The search process has failed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SearchText")
    End If
Else
    MessageBox.Show("The file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SearchText")
End If
//We assume that the GdViewer1 control has been properly integrated.
if (GdViewer1.DisplayFromFile("") == GdPictureStatus.OK)
{
    string text_to_find = "GdPicture";
    GdViewer1.ClearRect();
    bool text_found = GdViewer1.SearchText(text_to_find, 1, true, true);
    if (GdViewer1.GetStat() == GdPictureStatus.OK)
    {
        if (text_found && GdViewer1.IsRect())
            GdViewer1.CenterOnRect();
        else
            MessageBox.Show("The given text has not been found.", "GdViewer.SearchText");
    }
    else
        MessageBox.Show("The search process has failed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SearchText");
}
else
    MessageBox.Show("The file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SearchText");
See Also