/// <summary> /// Perform the search on the text box /// </summary> /// <param name="sender">Sending object</param> /// <param name="e">Parameters relating to the search event</param> protected void findDialog1_SearchRequested(object sender, SearchEventArgs e) { int startSearch; int endSearch; if (e.FirstSearch) { startSearch = originalSelectionStart; endSearch = Text.Length; } else { // First part of search is between character after current selection (inclusive) and the end of the // document (exclusive), or the original search position position (exclusive) if this is greater // than the current selection position startSearch = SelectionStart + SelectionLength; if (originalSelectionStart >= startSearch) { endSearch = originalSelectionStart; } else { endSearch = Text.Length; } } bool match; match = SubSearch(e.SearchRegularExpression, startSearch, endSearch); if (!match && endSearch == Text.Length) // no match? retry from the beginning if the original start position is before or equal to the current search { // second search is from the start of the document to the original search position (exclusive) match = SubSearch(e.SearchRegularExpression, 0, originalSelectionStart); if (match) { e.RestartedFromDocumentTop = true; // The user is informed that the search started from the top } } if (match) { e.Successful = true; } }
private void findDialog1_SearchRequested(object sender, SearchEventArgs e) { int num; if (base.SelectedIndices.Count > 0) { num = base.SelectedIndices[0]; } else { num = 0; } if (e.FirstSearch) { this.originalSelectionStart = num; } int count; if (this.originalSelectionStart > num) { count = this.originalSelectionStart; } else { count = base.Items.Count; } bool flag = this.SubSearch(e.SearchRegularExpression, num + 1, count); if (!flag && this.originalSelectionStart <= num) { flag = this.SubSearch(e.SearchRegularExpression, 0, this.originalSelectionStart); if (flag) { e.RestartedFromDocumentTop = true; } } if (flag) { e.Successful = true; } }
private void findDialog1_SearchRequested(object sender, SearchEventArgs e) { if (e.FirstSearch) { // Store the selection start position on the first search so that when all searches are complete // this fact can be reported to the user in the find dialog. originalSelectionStart = SelectedNode; } // First part of search is between item after current selection (inclusive) and the end of the // document (exclusive), or the original search position position (exclusive) if this is greater // than the current selection position TreeNode searchFromBelow = SelectedNode; SearchableTreeView.TreeSearchState treeSearchState = SearchableTreeView.TreeSearchState.NotStarted; // A SubSearch function is used to search part of the tree SubSearch(e.SearchRegularExpression, Nodes, searchFromBelow, originalSelectionStart, ref treeSearchState); if (treeSearchState == SearchableTreeView.TreeSearchState.MatchMade) { e.Successful = true;// We have a match } else if (treeSearchState != SearchableTreeView.TreeSearchState.HitEndNode) { // No match? We hit end of document // Retry from the beginning if the original start position is before or equal to the current selection e.RestartedFromDocumentTop = true; // The user is informed that the search started from the top treeSearchState = SearchableTreeView.TreeSearchState.Started; // Search first half of the document SubSearch(e.SearchRegularExpression, Nodes, null, originalSelectionStart, ref treeSearchState); if (treeSearchState == SearchableTreeView.TreeSearchState.MatchMade) { e.Successful = true; // We have a match } } }
protected void findDialog1_SearchRequested(object sender, SearchEventArgs e) { int num; int length; if (e.FirstSearch) { num = this.originalSelectionStart; length = this.Text.Length; } else { num = base.SelectionStart + this.SelectionLength; if (this.originalSelectionStart >= num) { length = this.originalSelectionStart; } else { length = this.Text.Length; } } bool flag = this.SubSearch(e.SearchRegularExpression, num, length); if (!flag && length == this.Text.Length) { flag = this.SubSearch(e.SearchRegularExpression, 0, this.originalSelectionStart); if (flag) { e.RestartedFromDocumentTop = true; } } if (flag) { e.Successful = true; } }
/// <summary> /// Instigate a search /// </summary> /// <remarks> /// Intended for use by FindDialog or FindForm only /// </remarks> internal bool Search() { // Set up new event args. 'First' flag is set depending on the display mode of the find form SearchEventArgs eventArgs = new SearchEventArgs(SearchRegularExpression, SearchMode == FindDialog.SearchModes.Ready); if (searchRequested == null) { throw new Exception("No search event supplied"); } searchRequested(this, eventArgs); // set the state of the search form depending on the result of the search if (eventArgs.Successful) { SearchMode = SearchModes.SearchAgain; return true; } if (eventArgs.FirstSearch) { SearchMode = SearchModes.SearchFailed; } else { SearchMode = SearchModes.SearchFinished; } return false; }
/// <summary> /// Perform the search on the list view /// </summary> /// <param name="sender">Sending object</param> /// <param name="e">Parameters relating to the search event</param> private void findDialog1_SearchRequested(object sender, SearchEventArgs e) { int selectionStart; int endSearch; // Calculate the first node for the search if (SelectedIndices.Count > 0) { selectionStart = SelectedIndices[0]; } else { // No selection - search from the top of the document selectionStart = 0; } // Store the selection start position on the first search so that when all searches are complete // this fact can be reported to the user in the find dialog. if (e.FirstSearch) { originalSelectionStart = selectionStart; } // Calculate the end point if (originalSelectionStart > selectionStart) { // Final node is before end of document - just search to there endSearch = this.originalSelectionStart; } else { endSearch = Items.Count; } // Search the first subsection - from current selection position to the end of the document, // or the original starting point. bool match = this.SubSearch(e.SearchRegularExpression, selectionStart + 1, endSearch); if (!match && (this.originalSelectionStart <= selectionStart)) { // No match .. search the first half of the document match = this.SubSearch(e.SearchRegularExpression, 0, this.originalSelectionStart); if (match) { // We may wish to tell the user we have started from the top of the document e.RestartedFromDocumentTop = true; } } if (match) { // A match was found - tell the user e.Successful = true; } }