GdPicture.NET.14
GdPicture14 Namespace / GdViewer Class / SearchText Method / SearchText(String,Int32,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.

If you set this parameter to 0, the currently defined highlighted regions changes to those recognized by this search. If you specify a value other than 0, the rectangle covered by the occurrence found is made the current rectangle of selection.

Set this parameter to true if you want to apply case-sensitive search, otherwise set it to false.
Example





In This Topic
SearchText(String,Int32,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, the method will fail.

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, be aware that this method changes highlighted regions or the rectangle of area selection depending on the Occurrence parameter as follows:

  1. The currently defined highlighted regions, if present, changes to the regions identified by all occurrences of the found text, if you search for all of them. You can use the RemoveAllRegions method before starting new search to ensure the previously defined regions will remove.
  2. The current rectangle of area selection changes to the text found if you search for the specific occurrence. You can identify it using the IsRect method or you can clear the previous rectangle's data using the ClearRect method.

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

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.

If you set this parameter to 0, the currently defined highlighted regions changes to those recognized by this search. If you specify a value other than 0, the rectangle covered by the occurrence found is made the current rectangle of selection.

CaseSensitive
Set this parameter to true if you want to apply case-sensitive search, 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 setting the Occurrence parameter to 0 causes, that regions determined by this search replace the currently defined highlighted regions. In addition to this, the current rectangle of selection changes to the text found using the Occurrence parameter greater than 0.

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