VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
Vintasoft.Imaging.Wpf.UI.VisualTools Namespace / WpfTextSelectionTool Class / FindText Methods / FindText(String,TextSearchMode,Boolean,Boolean) Method
Syntax Example Requirements SeeAlso
In This Topic
FindText(String,TextSearchMode,Boolean,Boolean) Method (WpfTextSelectionTool)
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 searchNext
A value indicating whether the text search must be continued.
As Boolean _
)
public void FindText(
System.String text,
TextSearchMode searchMode,
bool searchUp,
bool searchNext
)

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.
searchNext
A value indicating whether the text search must be continued.
Example

   
Public Partial Class TextSearchWindow   
    Inherits System.Windows.Window   
    '...
    Private _imageViewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewer = Nothing   
    Private _textSelectionTool As Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool = Nothing   
   
   
   
    Public Sub New()   
        '...
   
        ' create the text selection tool
        _textSelectionTool = New Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool(New System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(56, 0, 0, 255)))   
   
        ' subscribe to selection tool events
        AddHandler _textSelectionTool.TextSearched, New System.EventHandler(Of Vintasoft.Imaging.Text.TextSearchedEventArgs)(AddressOf _textSelectionTool_TextSearched)   
   
        ' sets the text selection tool as current tool
        _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.Wpf.UI.VisualTools.TextSearchMode.AllPages, False, newSearch)   
    End Sub   
   
    ''' <summary>
    ''' Text is searched.
    ''' </summary>
    Private Sub _textSelectionTool_TextSearched(sender As Object, args As Vintasoft.Imaging.Text.TextSearchedEventArgs)   
        ' if text is NOT found
        If args.FoundTextRegion Is Nothing Then   
            System.Windows.MessageBox.Show(String.Format("The specified text is not found: {0}", args.SearchEngine))   
        Else   
            ' if text is found
            ' go to the page, where text is found
            _textSelectionTool.ImageViewer.SetFocusedIndexSync(args.ImageIndex)   
   
            ' select the text region
            _textSelectionTool.SelectedRegion = args.FoundTextRegion   
   
            ' scroll to the searched text
            _textSelectionTool.ScrollToSelectedRegion()   
        End If   
    End Sub   
   
End Class


public partial class TextSearchWindow : System.Windows.Window
{
    //...
    Vintasoft.Imaging.Wpf.UI.WpfImageViewer _imageViewer = null;
    Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool _textSelectionTool = null;



    public TextSearchWindow()
    {
        //...

        // create the text selection tool
        _textSelectionTool = new Vintasoft.Imaging.Wpf.UI.VisualTools.WpfTextSelectionTool(
            new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(56, 0, 0, 255)));

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

        // sets the text selection tool as current tool
        _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.Wpf.UI.VisualTools.TextSearchMode.AllPages, false, newSearch);
    }

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

            // select the text region
            _textSelectionTool.SelectedRegion = args.FoundTextRegion;

            // scroll to the searched text
            _textSelectionTool.ScrollToSelectedRegion();
        }
    }

}

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