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, 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:
- 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.
- 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 As String, _
ByVal As Integer, _
ByVal As Boolean, _
ByVal As Boolean _
) As Boolean
public bool SearchText(
string ,
int ,
bool ,
bool
)
public function SearchText(
: String;
: Integer;
: Boolean;
: Boolean
): Boolean;
public function SearchText(
: String,
: int,
: boolean,
: boolean
) : boolean;
public: bool SearchText(
string* ,
int ,
bool ,
bool
)
public:
bool SearchText(
String^ ,
int ,
bool ,
bool
)
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 are enriched with 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.
- 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.
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