VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
Vintasoft.Imaging.Wpf.UI.VisualTools Namespace / WpfTextSelectionTool Class / FindText Methods / FindText(String,Boolean,TextSearchMode,Boolean,Boolean) Method
Синтаксис Example Требования Смотрите также
В этом разделе
    FindText(String,Boolean,TextSearchMode,Boolean,Boolean) Метод (WpfTextSelectionTool)
    В этом разделе
    Ищет текстовую строку, начиная с текущей страницы.
    Синтаксис
    'Declaration
    
    Public Overloads Sub FindText( _
    ByVal text
    Текст для поиска.
    As System.String, _
    ByVal ignoreCase
    Значение, указывающее, следует ли игнорировать чувствительность к регистру.
    As Boolean, _
    ByVal searchMode
    Режим поиска текста.
    As TextSearchMode, _
    ByVal searchUp
    Значение, указывающее, следует ли искать текст с текущей позиции в документе до начала документа/страницы.
    As Boolean, _
    ByVal searchNext
    Значение, указывающее, следует ли продолжать поиск текста.
    As Boolean _
    )
    public: void FindText(
    System.String text,
    bool ignoreCase,
    TextSearchMode searchMode,
    bool searchUp,
    bool searchNext
    )

    Parameters

    text
    Текст для поиска.
    ignoreCase
    Значение, указывающее, следует ли игнорировать чувствительность к регистру.
    searchMode
    Режим поиска текста.
    searchUp
    Значение, указывающее, следует ли искать текст с текущей позиции в документе до начала документа/страницы.
    searchNext
    Значение, указывающее, следует ли продолжать поиск текста.
    Пример

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

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также