60 lines
1.9 KiB
Plaintext
60 lines
1.9 KiB
Plaintext
''' <summary>
|
|
''' This class provides two subroutines used to:
|
|
''' Find (find the first instance of a search term)
|
|
''' Find Next (find other instances of the search term after the first one is found)
|
|
''' </summary>
|
|
''' <remarks></remarks>
|
|
|
|
Public Class frmFind
|
|
|
|
Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
|
|
|
|
Dim StartPosition As Integer
|
|
Dim SearchType As CompareMethod
|
|
|
|
If chkMatchCase.Checked = True Then
|
|
SearchType = CompareMethod.Binary
|
|
Else
|
|
SearchType = CompareMethod.Text
|
|
End If
|
|
|
|
StartPosition = InStr(1, frmMain.rtbDoc.Text, txtSearchTerm.Text, SearchType)
|
|
|
|
If StartPosition = 0 Then
|
|
MessageBox.Show("String: " & txtSearchTerm.Text.ToString() & " not found", "No Matches", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
|
|
Exit Sub
|
|
End If
|
|
|
|
frmMain.rtbDoc.Select(StartPosition - 1, txtSearchTerm.Text.Length)
|
|
frmMain.rtbDoc.ScrollToCaret()
|
|
frmMain.Focus()
|
|
|
|
End Sub
|
|
|
|
|
|
Private Sub btnFindNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindNext.Click
|
|
|
|
Dim StartPosition As Integer = frmMain.rtbDoc.SelectionStart + 2
|
|
Dim SearchType As CompareMethod
|
|
|
|
If chkMatchCase.Checked = True Then
|
|
SearchType = CompareMethod.Binary
|
|
Else
|
|
SearchType = CompareMethod.Text
|
|
End If
|
|
|
|
StartPosition = InStr(StartPosition, frmMain.rtbDoc.Text, txtSearchTerm.Text, SearchType)
|
|
|
|
If StartPosition = 0 Then
|
|
MessageBox.Show("String: " & txtSearchTerm.Text.ToString() & " not found", "No Matches", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
|
|
Exit Sub
|
|
End If
|
|
|
|
frmMain.rtbDoc.Select(StartPosition - 1, txtSearchTerm.Text.Length)
|
|
frmMain.rtbDoc.ScrollToCaret()
|
|
frmMain.Focus()
|
|
|
|
End Sub
|
|
|
|
|
|
End Class |