GdPicture.NET Reference Guide
SearchText(String,Int32,Boolean,Boolean,Boolean) Method
Example 





GdPicture14.WPF Namespace > GdViewer Class > SearchText Method : SearchText(String,Int32,Boolean,Boolean,Boolean) Method
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/true if you want to apply case-sensitive search, otherwise set it to False/false.
Set this parameter to True/true if you want to search for the whole words only, otherwise set it to False/false.
Set this parameter to True/true if you want to search applying the ordinal (binary) sort rules, otherwise set it to False/false. An ordinal comparison compares strictly on the numeric character values, that means it does not respect accents.
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.

You can benefit from selecting the comparison option using this method, in other words, you can search respecting accents or not in the given text expression.

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

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/true if you want to apply case-sensitive search, otherwise set it to False/false.
WholeWords
Set this parameter to True/true if you want to search for the whole words only, otherwise set it to False/false.
OrdinalComparison
Set this parameter to True/true if you want to search applying the ordinal (binary) sort rules, otherwise set it to False/false. An ordinal comparison compares strictly on the numeric character values, that means it does not respect accents.

Return Value

True/true if the given text expression has been found on the current page according to the specified parameters, otherwise False/false. Please always use the GetStat method to determine if this method has been successful.
Remarks
Please note that this method is only useful for text-based document formats, like DOCX, TXT, RTF and PDF.

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, 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, 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, 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, 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

Reference

GdViewer Class
GdViewer Members
Overload List
GetTextOccurrenceCount(Int32,String,Boolean,Boolean) Method
GetSelectedTextRegions Method
GetSelectedText Method
ClearSelectedText Method
RegionCount Method