Hello Code Community, This is my first time posting. I hope this makes sense.
I am using Visual Studio 2005.
I am working on a form that basically loads file of data and the user is allowed to edit the data in many ways. I am having trouble adding SEARCH TEXT tool to the application.
I have one form called frmMain. It contains a big Rich Text Box. I have created buttons to open and close data files (most of them are normal txt files). I have a button named btnSearch. When clicked a new form named frmSearch pops up. This form has a textbox for the user to enter the text they wish to search for. Then when they press the Search button, it is supposed to search the file loaded into frmMain for the entered text and highlight it. Much like Microsoft Word or a search function in Firefox or IE.
My problem is that when the search takes place the first instance of the text is highlighted, but if there are more of the texts in the file, the screen or page does not move down for the user to see the other instances. If there are 5 instances of the text JONES, it will find all 5 on each click of the search button, but the user can only see the ones that are already on the screen.
How can I make it so that if there are instances of the text in pages below, the page move according to the instance of the text that is found.
MY CODE on frmSearch:
Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
If String.IsNullOrEmpty(txtSearch.Text) Then
MessageBox.Show("No text to search")
Else
SearchFunction(frmMain.rtb.Text.ToLower, txtSearch.Text.ToLower)
End If
End Sub
Dim StartIndex As Integer
Private Sub SearchFunction(ByVal Text As String, ByVal SearhText As String)
StartIndex = Text.IndexOf(SearhText, StartIndex + SearhText.Length)
If StartIndex <> -1 Then
frmMain.rtb.Select(StartIndex, SearhText.Length)
frmMain.rtb.Select()
Else
MessageBox.Show("Designer has finished searching the data")
StartIndex = 0
End If
End Sub
End Class
Again I hope this makes sense to the community, I apologize if the problems isn't clear. I tried to explain it as best as possible. Any help or comments is much appreciated. Thank You.