How to create a Find Next function/button

  • Thread starter Thread starter B3nch
  • Start date Start date
B

B3nch

Guest
HI Good day!

Could you give me some help to my program?I would like to create a search box that will find the data inside the richtextbox.I would like to know how the Find next button on notepad working.

Here is my code.

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


If (OpenFileDialog1.ShowDialog = DialogResult.OK) Then
RichTextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
Else
MsgBox("Not Found")

End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim index As Integer = 0
Dim temp As String = RichTextBox1.Text
RichTextBox1.Text = ""
RichTextBox1.Text = temp


While index < RichTextBox1.Text.LastIndexOf(TextBox1.Text)
RichTextBox1.Find(TextBox1.Text, index, RichTextBox1.TextLength, RichTextBoxFinds.None)
RichTextBox1.SelectionBackColor = Color.Red
index = RichTextBox1.Text.IndexOf(TextBox1.Text, index) + 1


End While

'Dim a As String
'Dim b As String

' a = InputBox("Enter")
' b = InStr(RichTextBox1.Text, a)
' If b Then
' RichTextBox1.Focus()
' RichTextBox1.SelectionLength = Len(a)
' Else
' MsgBox("Not Found")
' End If

End Sub






End Class

Continue reading...
 
Back
Top