I'm making a notepad program and i want the user to be able to search for text. I got the code working for the "Find Next" button, but I cant get the code for the "Find Previous" button.
Here's what I have for Find Next:
Here's what I have for Find Previous:Code:Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Dim x As Integer
Dim opt As RichTextBoxFinds = 0
If chkCase.Checked Then opt = opt Or RichTextBoxFinds.MatchCase
x = CType(frmMain.TabControl.SelectedTab.Controls.Item(0), RichTextBox).Find(txtFind.Text, PlaceHolder, opt)
If x < 0 Then
If MessageBox.Show("There are no more occurances of " & txtFind.Text & vbCrLf & "Start at begining?", "Can't Find", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
PlaceHolder = 0
btnNext.PerformClick()
End If
End If
PlaceHolder = CType(frmMain.TabControl.SelectedTab.Controls.Item(0), RichTextBox).SelectionStart + 1
CType(frmMain.TabControl.SelectedTab.Controls.Item(0), RichTextBox).Focus()
End Sub
I just can't seem to make it work. I've been messing with it and trying all sorts of different options, it just keeps messing up.
Any help is greatly appreciated!Code:Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
Dim x As Integer
Dim opt As RichTextBoxFinds = 0
If chkCase.Checked Then opt = opt Or RichTextBoxFinds.MatchCase
x = CType(frmMain.TabControl.SelectedTab.Controls.Item(0), RichTextBox).Find(txtFind.Text, PlaceHolder, opt)
If x < 0 Then
If MessageBox.Show("There are no more occurrences of " & txtFind.Text & vbCrLf & "Start at begining?", "Word or Phrase Not Found", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
PlaceHolder = 0
btnNext.PerformClick()
End If
End If
PlaceHolder = CType(frmMain.TabControl.SelectedTab.Controls.Item(0), RichTextBox).SelectionStart - 1
CType(frmMain.TabControl.SelectedTab.Controls.Item(0), RichTextBox).Focus()
End Sub
~Thanks in advance
