VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
Vintasoft.Imaging.UI.VisualTools Namespace / TextSelectionTool Class / FindText Methods / FindText(String,TextSearchMode,Boolean,Boolean) Method
Syntax Example Requirements SeeAlso
In This Topic
FindText(String,TextSearchMode,Boolean,Boolean) Method (TextSelectionTool)
In This Topic
Searches the text string starting from current page.
Syntax
'Declaration

Public Overloads Sub FindText( _
ByVal text
Text to search.
As System.String, _
ByVal searchMode
Text search mode.
As TextSearchMode, _
ByVal searchUp
A value indicating whether the text must be searched from current position in document to the beginning of document/page.
As Boolean, _
ByVal searchFromStart
A value indicating whether the text search must be started from the beginning.
As Boolean _
)
public void FindText(
System.String text,
TextSearchMode searchMode,
bool searchUp,
bool searchFromStart
)

Parameters

text
Text to search.
searchMode
Text search mode.
searchUp
A value indicating whether the text must be searched from current position in document to the beginning of document/page.
searchFromStart
A value indicating whether the text search must be started from the beginning.
Example


Public Partial Class TextSearchForm
    Inherits System.Windows.Forms.Form
    ' ...
    Private _imageViewer As Vintasoft.Imaging.UI.ImageViewer = Nothing
    Private _textSelectionTool As Vintasoft.Imaging.UI.VisualTools.TextSelectionTool = Nothing



    Public Sub New()
        ' ...

        ' create the text selection tool
        _textSelectionTool = New Vintasoft.Imaging.UI.VisualTools.TextSelectionTool(New System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(56, System.Drawing.Color.Blue)))

        ' subscribe to the text selection tool events
        AddHandler _textSelectionTool.TextSearched, New System.EventHandler(Of Vintasoft.Imaging.Text.TextSearchedEventArgs)(AddressOf _textSelectionTool_TextSearched)

        ' sets the text selection tool as the current tool in image viewer
        _imageViewer.VisualTool = _textSelectionTool
    End Sub



    ''' <summary>
    ''' Starts the text search from the focused page in viewer.
    ''' </summary>
    Public Sub SearchText(text As String, newSearch As Boolean)
        ' specify that non case sensitive text must be searched
        Dim searchEngine As Vintasoft.Imaging.Text.TextSearchEngine = Vintasoft.Imaging.Text.TextSearchEngine.Create(text, True)
        ' find text in all pages
        _textSelectionTool.FindText(searchEngine, Vintasoft.Imaging.UI.VisualTools.TextSearchMode.AllPages, False, newSearch)
    End Sub

    ''' <summary>
    ''' Text is searched.
    ''' </summary>
    Private Sub _textSelectionTool_TextSearched(sender As Object, e As Vintasoft.Imaging.Text.TextSearchedEventArgs)
        ' if text is NOT found
        If e.FoundTextRegion Is Nothing Then
            System.Windows.Forms.MessageBox.Show(String.Format("The specified text is not found: {0}", e.SearchEngine))
        Else
            ' if text is found
            ' go to the page, where text is found
            _imageViewer.FocusedIndex = e.ImageIndex
            ' select the text region
            _textSelectionTool.SelectedRegion = e.FoundTextRegion
        End If
    End Sub

End Class


public partial class TextSearchForm : System.Windows.Forms.Form
{
    // ...
    Vintasoft.Imaging.UI.ImageViewer _imageViewer = null;
    Vintasoft.Imaging.UI.VisualTools.TextSelectionTool _textSelectionTool = null;



    public TextSearchForm()
    {
        // ...

        // create the text selection tool
        _textSelectionTool = new Vintasoft.Imaging.UI.VisualTools.TextSelectionTool(
            new System.Drawing.SolidBrush(
                System.Drawing.Color.FromArgb(56, System.Drawing.Color.Blue)));

        // subscribe to the text selection tool events
        _textSelectionTool.TextSearched +=
            new System.EventHandler<Vintasoft.Imaging.Text.TextSearchedEventArgs>(_textSelectionTool_TextSearched);

        // sets the text selection tool as the current tool in image viewer
        _imageViewer.VisualTool = _textSelectionTool;
    }



    /// <summary>
    /// Starts the text search from the focused page in viewer.
    /// </summary>
    public void SearchText(string text, bool newSearch)
    {
        // specify that non case sensitive text must be searched
        Vintasoft.Imaging.Text.TextSearchEngine searchEngine =
            Vintasoft.Imaging.Text.TextSearchEngine.Create(text, true);
        // find text in all pages
        _textSelectionTool.FindText(searchEngine,
            Vintasoft.Imaging.UI.VisualTools.TextSearchMode.AllPages, false, newSearch);
    }

    /// <summary>
    /// Text is searched.
    /// </summary>
    private void _textSelectionTool_TextSearched(object sender, Vintasoft.Imaging.Text.TextSearchedEventArgs e)
    {
        // if text is NOT found
        if (e.FoundTextRegion == null)
        {
            System.Windows.Forms.MessageBox.Show(string.Format("The specified text is not found: {0}", e.SearchEngine));
        }
        // if text is found
        else
        {
            // go to the page, where text is found
            _imageViewer.FocusedIndex = e.ImageIndex;
            // select the text region
            _textSelectionTool.SelectedRegion = e.FoundTextRegion;
        }
    }

}

Requirements

Target Platforms: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

See Also