←Select platform

DocumentViewerFindTextStart Enumeration

Summary

An enumeration for choosing the starting position of a DocumentViewerText.Find operation.

Syntax
C#
C++/CLI
public enum DocumentViewerFindTextStart 
public: 
   enum class DocumentViewerFindTextStart sealed 
Members
ValueMemberDescription
0BeginPositionDefault. Indicates that the search should run from the provided [DocumentViewerFindTextStart.BeginPosition] to the DocumentViewerFindText.EndPosition (or top of page 1 and bottom of the last page, if these values were null). This results in one total search from begin to end.
1InSelectionSetting this value to DocumentViewerFindText.Start indicates that the search should begin at the first character inside the first text selection in the document. This position may be either DocumentViewerText.SelectedTextBegin or DocumentViewerText.SelectedTextEnd, depending on the direction of the search.

If no text is selected, DocumentViewerFindText.Start works like [DocumentViewerFindTextStart.BeginPosition] (the default).

If the text selection is within the bounds created by DocumentViewerFindText.BeginPosition and DocumentViewerFindText.EndPosition, this may result in two searches.

  • The first search will occur from the first character in the selection to the position indicated by DocumentViewerFindText.EndPosition. If the first character in the selection is before the beginPosition in the direction of the search, this means only one search is conducted, from the beginPosition to the endPosition. If the first character in the selection is after the endPosition in the direction of the search, no results will be returned.

  • If DocumentViewerFindText.Loop or DocumentViewerFindText.FindAll is set to true, then a second search may be conducted from the beginPosition to the character before the first character in the selection, provided that the first character in the selection was within the bounds of the search.

This behavior is similar to that in [DocumentViewerFindTextStart.AfterSelection], but with the first character in the text selection instead of the character after the end of the selection. Effectively, DocumentViewerFindTextStart.InSelection will search the selection first, and DocumentViewerFindTextStart.AfterSelection will not.

When using DocumentViewerFindText.SelectFirstResult, searching from the first character of the selection may be useful for “live update” search actions that will continue to add on to the selected text as long as it continues to match DocumentViewerFindText.Text. For example, if “L” is the selected text from a previous search for “L”, and the rest of the text is -“ead”, then successive searches of “L”, “Le”, “Lea”, and “Lead” will add to the selected item instead of searching for a new match each time.

2AfterSelectionSetting this value to DocumentViewerFindText.Start indicates that the search should begin at the first character after the last text selection in the document. This position may be one character before or after DocumentViewerText.SelectedTextBegin or DocumentViewerText.SelectedTextEnd, depending on the direction of the search. If the search is forward / down the page, the starting point will be the character after DocumentViewerText.SelectedTextEnd; if the search is backward / up the page, the starting point will be the character before DocumentViewerText.SelectedTextBegin.

If no text is selected, DocumentViewerFindText.Start works like FindTextStart.BeginPosition (the default).

If the text selection is within the bounds created by DocumentViewerFindText.BeginPosition and DocumentViewerFindText.EndPosition, two searches can result.

The first search will occur from the starting point mentioned above to the position indicated by DocumentViewerFindText.EndPosition. If the starting position is before the beginPosition in the direction of the search, this means only one search is conducted, from the beginPosition to the endPosition. If the starting position is after the endPosition in the direction of the search, no results will be returned.

If DocumentViewerFindText.Loop or DocumentViewerFindText.FindAll is set to true, then a second search may be conducted from the [beginPosition] to the character before the starting point, provided that the starting point was within the bounds of the search as described above.

This behavior is similar to that in [DocumentViewerFindTextStart.InSelection], but with the first character after the text selection instead of the character inside the selection. Effectively, [DocumentViewerFindTextStart.InSelection] will search the selection first, and [DocumentViewerFindTextStart.AfterSelection] will not.

When using DocumentViewerFindText.SelectFirstResult, searching from the first character after the selection is useful for “Find Next” and “Find Previous” operations that cycle through all the matches in the bounds.

3ManualPositionIndicates that the search should start from DocumentViewerFindText.ManualStartPosition .

If this value is provided to DocumentViewerFindText.Start, the search operation will use the value of DocumentViewerFindText.ManualStartPosition as the starting point. If DocumentViewerFindText.ManualStartPosition is null, the search will act as if DocumentViewerFindText.BeginPosition was passed to DocumentViewerFindText.Start instead.

See DocumentViewerFindText.ManualStartPosition for more information.

Remarks

DocumentViewerFindTextStart is an enum type that chooses where the DocumentViewerText.Find method will start its search within the provided begin and end parameters. While the DocumentViewerFindText.BeginPosition and DocumentViewerFindText.EndPosition properties specify the bounds of the search, it is the DocumentViewerFindText.Start that determines where the algorithm will begin searching.

If DocumentViewerFindText.Loop or DocumentViewerFindText.FindAll is true, then the text search operation will be cut into two parts – one search from the start to the endPosition, and another from the beginPosition to the character before the start.

History

19.0.0.49
Added
Example
C#
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Document; 
using Leadtools.Document.Viewer; 
using Leadtools.Codecs; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Ocr; 
 
 
var text = _documentViewer.Text; 
 
// Make sure we get the page text if necessary 
text.AutoGetText = true; 
 
// We will find all matches of "LEAD", ignoring the case 
var options = new DocumentViewerFindText(); 
 
// The text 
options.Text = "LEAD"; 
// Ignore case 
options.MatchCase = false; 
// Any word that contains the phrase 
options.WholeWordsOnly = false; 
 
// Find all results in the bounds, not just the first 
options.FindAll = true; 
 
// Highlight the results in the View 
options.RenderResults = true; 
// Optionally change the highlight color 
//DocumentViewerText.FoundTextBrush = new SolidBrush(Color.FromArgb(52, Color.Brown)); 
 
// Set the bounds 
bool isFindingNext = true; 
// We set the bounds as the whole document, but below we can specify to start wherever text is selected 
// or at the current page 
var topOfFirstPage = DocumentViewerTextPosition.CreateBeginOfPage(1); 
var bottomOfLastPage = DocumentViewerTextPosition.CreateEndOfPage(_documentViewer.PageCount); 
if (isFindingNext) 
{ 
   // Make the beginning bound "higher up" the page so we search "down" the page. 
   options.BeginPosition = topOfFirstPage; 
   options.EndPosition = bottomOfLastPage; 
} 
else 
{ 
   // Make the beginning bound "lower down" the page so we search "up" the page. 
   options.BeginPosition = bottomOfLastPage; 
   options.EndPosition = topOfFirstPage; 
} 
 
// Select the first result in the View (automatically scrolls View also) 
options.SelectFirstResult = true; 
 
if (text.HasAnySelectedText) 
{ 
   // Setting this value to AfterSelection allows us to search forward from the selection, so multiple 
   // uses of this same options object will cycle us through all the matches! 
   // (If no selected text actually exists, search will default to beginPosition.) 
   options.Start = DocumentViewerFindTextStart.AfterSelection; 
} 
else 
{ 
   // We could start at the begin position, but it makes more UI sense to start from the user's current page. 
   // Search will loop back around to the begin position - this just changes the starting point and order of results. 
   options.Start = DocumentViewerFindTextStart.ManualPosition; 
   if (isFindingNext) 
      options.ManualStartPosition = DocumentViewerTextPosition.CreateBeginOfPage(_documentViewer.CurrentPageNumber); 
   else 
      options.ManualStartPosition = DocumentViewerTextPosition.CreateEndOfPage(_documentViewer.CurrentPageNumber); 
} 
 
// If we were just looking for the first match, we could use "Loop" to loop around 
// if we found nothing between the start position and the end bound. 
//options.Loop = true; 
 
// You will likely want to clear the previous highlighted results 
// on the screen so only our new results will show. 
text.ClearRenderedFoundText(); 
 
// Search 
var results = text.Find(options); 
int resultsCount = results != null ? results.Count : 0; 
 
if (resultsCount > 0) 
   Console.WriteLine(string.Format("Found {0} results", resultsCount)); 
else 
   Console.WriteLine("No matches found."); 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document.Viewer.WinForms Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.